【问题标题】:How can I pass a Text string as a PHP Exec command如何将文本字符串作为 PHP Exec 命令传递
【发布时间】:2013-03-14 02:18:03
【问题描述】:

我正在尝试使用 PHP Exec 命令行将文本字符串作为变量传递,但没有传递整个文本。

文字是这样的:

$title_page = 'Channel | This is the channels title';

那么执行行是:

exec("$path_to_php $emailer $article_sub_security_var $article_id > /dev/null &");

我是这样检索它们的:

$article_sub_security_var = $_SERVER['argv'][1];
$article_id = $_SERVER['argv'][2];
$page_title = $_SERVER['argv'][3];

除了 $page_title 之外,命令行工作正常。它只返回字符串的一部分,而不是全部。

非常感谢任何建议通过它。

【问题讨论】:

  • 我在 exec 语句中的任何地方都没有看到 $title_page 甚至 $page_title :-/

标签: php string text arguments exec


【解决方案1】:

除了 $page_title 之外,命令行工作正常。它只返回字符串的一部分,而不是全部。

我猜你的问题是你的页面标题中的|(管道),尝试在$title_page之前使用escapeshellcmd

【讨论】:

  • 对不起。该命令确实包含 $page_title 。我的错误。 darthmaim - 你能告诉我代码在 $page_title 上的样子吗?它会进入 exec 命令行吗?所以是这样的: exec("$path_to_php $emailer $article_sub_security_var $article_id escapeshellcmd($page_title) > /dev/null &");
  • 我刚刚尝试使用 escapeshellcmd($page_title) 但它不起作用。我尝试删除管道,但它似乎只返回文本字符串的第一个单词。它似乎返回任何文本直到出现第一个空格。
  • 您必须在引号中包含$page_title ("),因为它包含空格,例如:exec("$path_to_php $emailer $article_sub_security_var $article_id \"$page_title\" > /dev/null &");
  • 谢谢。这完美无缺。我也刚刚尝试过也可以使用的 escapeshellarg。非常感谢。
猜你喜欢
  • 2023-03-30
  • 2015-11-20
  • 1970-01-01
  • 2017-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-21
相关资源
最近更新 更多