【问题标题】:php calling variable within complex quotationsphp在复杂引号内调用变量
【发布时间】:2012-03-02 02:51:16
【问题描述】:

我正在尝试使用我需要发送到 Windows CLI 的命令调用变量,但没有运气,如果你能帮助我

$imagename = 123;

$test = ('C:\Windows\System32\cmd.exe /c "rundll32.exe C:\Windows\System32\shimgvw.dll,ImageView_PrintTo /pt "c:\pathtodirectory\$imagename" "photoprint""');
echo $test

$imagename 目前的值为 123,但我无法在多个引用中调用它,请帮助。

谢谢。

【问题讨论】:

  • 函数和方法被“调用”,变量被“使用”、“引用”或“插值”。
  • 我不认为引号会起作用,即使在 PHP 之外。您在引用块内有未转义的引用块。我认为 Windows 会在你解决任何其他问题之前解决这个问题。
  • 很抱歉被调用的 vs 使用了我只是为了让它工作而遇到困难,如果我将它与文件名一起使用而不是尝试使用变量,该命令确实有效,只是我很困惑引用了这么多

标签: php variables quotations


【解决方案1】:

这个呢?

$imagename = 123;
$test = 'C:\Windows\System32\cmd.exe /c "rundll32.exe C:\Windows\System32\shimgvw.dll,ImageView_PrintTo /pt "c:\pathtodirectory\\' . $imagename . '" "photoprint"';
echo $test;

【讨论】:

  • 是的,我可以将 $test 与 exec 或 shell_exec 一起使用吗?
  • exec()的第二个参数将是一个数组,包含命令输出的每一行; shell_exec() 返回一个包含命令输出的字符串。这是你的选择。
【解决方案2】:

您的初始字符串在单引号内,PHP 不会解析单引号内的变量。

试试 $test = ("C:\Windows\System32\cmd.exe /c \"rundll32.exe C:\Windows\System32\shimgvw.dll,ImageView_PrintTo /pt \"c:\pathtodirectory\$imagename\" \"photoprint\"\"");

$test = ('C:\Windows\System32\cmd.exe /c "rundll32.exe C:\Windows\System32\shimgvw.dll,ImageView_PrintTo /pt ' . "\"c:\pathtodirectory\$imagename\"" . ' "photoprint""');

【讨论】:

  • C:\Windows\System32\cmd.exe /c "rundll32.exe C:\Windows\System32\shimgvw.dll,ImageView_PrintTo /pt "c:\pathtodirectory$imagename" "photoprint""我仍然得到 $imagename 而不是 123
猜你喜欢
  • 2012-05-17
  • 2014-12-31
  • 1970-01-01
  • 2018-01-17
  • 2019-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-05
相关资源
最近更新 更多