Reputation: 304
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
Upvotes: 2
Views: 953
Reputation: 59701
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
Upvotes: 1
Reputation: 304
@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 %*
Upvotes: 2