错误 - 使用批处理文件运行 php 文件


Error - to run php file using batch file

我正在使用Windows机器。我想运行一个在W-Drive(网络驱动器)上的php文件,而我的bat文件在桌面上。我不明白为什么,但不知何故它没有执行我的 php 文件。我的代码看起来像这样

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

它也不会显示错误参考了如何从批处理文件运行 php 脚本

任何建议我哪里出错了?

谢谢

此外,当我运行将从浏览器中删除特殊字符的 php 脚本时,我首先收到此错误 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然后如果我再次刷新,它会执行而不会出错。

我的 php scipt 看起来像这样

<?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));
}
?>

请告诉我哪里出错了

@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 %*

我想你忘记了扩展.exe

所以把它改成这样:

"D:'xampp'php'php.exe"

否则请尝试以下操作:

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

编辑:

如果要更改file php脚本将从batch文件location执行,因此您必须像这样cd php脚本:

cd W:'Automation'Task'csv-file

因此,有了这个,您的 php 脚本将从 php 脚本位置执行