0

私は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

4

2 に答える 2

4

エスケープシェルアーグを使用する

$url = escapeshellarg($url);
于 2012-08-20T02:32:03.547 に答える
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
~ $ 
于 2012-08-20T02:31:58.860 に答える