我正在使用PHP的shell_exec()
通过命令行执行程序,并将URL作为参数传递给它。
问题:程序似乎只收到参数的截断版本。 PHP传递参数
http://www.mysite.com/Men/T-Shirts-Vests/Cat/pgecategory.aspx?cid=7616&parentID=-1&pge=0&pgeSize=200&sort=1
但程序收到
http://www.mysite.com/Men/T-Shirts-Vests/Cat/pgecategory.aspx?cid=7616
如何防止&
之后被截断?
PHP
$url = 'http://www.mysite.com/Men/T-Shirts-Vests/Cat/pgecategory.aspx?cid=7616&parentID=-1&pge=0&pgeSize=200&sort=1';
$script = path('base')."application/phantomjs/httpget.js";
$output = shell_exec("phantomjs $script $url");
httpget.js
// Get URL from command line parameter
var system = require('system');
var url = system.args[1];
console.log(url);
输出
http://www.mysite.com/Men/T-Shirts-Vests/Cat/pgecategory.aspx?cid=7616
答案 0 :(得分:4)
$url = escapeshellarg($url);
答案 1 :(得分:0)
引用你的字符串:
$url = 'http://www.mysite.com/Men/T-Shirts-Vests/Cat/pgecategory.aspx?cid=7616&parentID=-1&pge=0&pgeSize=200&sort=1';
$script = path('base')."application/phantomjs/httpget.js";
$output = shell_exec("phantomjs $script \"$url\"");
例如,请考虑以下事项:
~ $ echo foo&bar
[1] 25361
foo
-bash: bar: command not found
[1]+ Done echo foo
~ $
VS
~ $ echo "foo&bar"
foo&bar
~ $