【问题标题】:Batch string replace批量字符串替换
【发布时间】:2011-04-08 10:38:09
【问题描述】:

我有一个这样的变量

"Folder With Spaces/filename.ext"

当我通过 PHP 的系统命令将它传递给我的程序时,参数由空格分隔

system("batch.bat Folder With Spaces/filename.ext");

所以我是这样的

system("batch.bat Folder_With_Spaces/filename.ext");

现在有没有办法在批处理程序中将_ 替换为

【问题讨论】:

  • 什么是批处理不能用PHP做的?

标签: php regex batch-file replace


【解决方案1】:

只需将带有空格的参数用引号括起来即可。

system("batch.bat \"Folder With Spaces/filename.ext\"");

【讨论】:

    【解决方案2】:

    在你的批处理文件中试试这个:

    set str=hello_world_try_this
    set str=%str:_= %
    echo.%str%
    

    【讨论】:

      【解决方案3】:

      你可能想试试 escapeshellcmd(),像这样:

      $path = escapeshellcmd("Folder With Spaces/filename.ext");  
      system("batch.bat \"$path\"");
      

      【讨论】:

      • ... 这对有问题的字符串完全没有任何作用。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 2015-07-17
      • 1970-01-01
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多