2

I am using a windows machine. I want to run a php file which is on W-Drive (network drive) and my bat file is on desktop. I don't understand why but somehow it is not executing my php file. My code looks like this

@echo call to php script
@echo OFF
"D:\xampp\php\php" W:\Automation\Task\csv-file\delete-special-chars.php %*
timeout /t 60
pause

It does not show errors either Took reference from how to run php script from batch file

Any suggestion where am I going wrong?

Thanks

Also when I run php script which will delete special characters from browser I first get this error Notice: iconv(): Detected an incomplete multibyte character in input string in /opt/lampp/htdocs/Wdrive/Automation/Task/csv-file/delete-special-chars.php on line 17 and then if i refresh again it execute without error.

My php scipt looks like this

<?php

foreach (glob("*.csv") as $file) 
{
    $contents = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

    $csvRows = array_map('str_getcsv', $contents);

    $output_array = array();

    foreach($csvRows as $row) 
    {
        // echo $row[0] . "\n"; // Will output  data contained in the first column

        $input = $row[0]; // original text

        $output = iconv("utf-8", "ascii//TRANSLIT//IGNORE", $input);

        $output_array[] =  preg_replace("/^'|[^A-Za-z0-9\s-]|'$/", '', $output); // lets remove utf-8 special characters except blank spaces

        // echo $output; // Results in: Foo Bar Zacarias ASABAD Ferreira
    }

    file_put_contents($file, implode("\n", $output_array));
}
?>

Please suggest me where am I going wrong

2 Answers 2

2
@echo call to php script to delete all the special characters
@echo OFF
W:

cd Automation\Task\csv-file
start "Start PHP" "D:\xampp\php\php.exe" -f delete-special-chars.php %*
Sign up to request clarification or add additional context in comments.

Comments

1

I think you forgot the extension .exe

So change it to this:

"D:\xampp\php\php.exe"

Otherwise try this:

start "Start PHP" "D:\xampp\php\php.exe" -f delete-special-chars.php

EDIT:

If you want to change something in a file the php script get's executed from the batch file location so you have to cd to the php script like this:

cd W:\Automation\Task\csv-file

So with this your php script gets executed from the php script location

6 Comments

Sorted :D Thanks to show me the issue. I have edited the answer
@deepkataria So it works now? what was the key to the solution?
W: -this will go in w drive cd Automation\Task\csv-file this will go to my folder where php script resides start "Start PHP" "D:\xampp\php\php.exe" -f delete-special-chars.php %* this will run my php script
@deepkataria Nice that you got the solution! (BTW: 1. an upvote would be nice :D for me effort(you don't have to!) 2. you can accept your own answer if you want)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.