好吧所以我使用下面的这个函数来创建一个我需要在php脚本中使用文本和变量的字符串
$result_string = "/usr/local/bin/casperjs test.js " . $proxy . " " . $button . " 2>&1";
这是我看到的输出
/usr/local/bin/casperjs test.js 192.192.192.0 81.88.88.88 2>&1
但问题是我需要在输出中添加“ - 我需要输出看起来像这样
/usr/local/bin/casperjs test.js "192.192.192.0" "81.88.88.88" 2>&1
我尝试了很多方法在两个变量周围添加“”而不影响功能,但仍然无法做到这一点
答案 0 :(得分:3)
有两种选择。要么使用单引号,要么转义双引号:
单引号:
$result_string = '/usr/local/bin/casperjs test.js "' . $proxy . "' '" . $button . ' 2>&1';
转义双引号:
$result_string = "/usr/local/bin/casperjs test.js \"" . $proxy . "\" \"" . $button . "\" 2>&1";
答案 1 :(得分:1)
你可以逃避“with \
\"
或者你可以用'
包装你的字符串'/usr/local/bin/casperjs test.js "...'
此外,您应该阅读并学习PHP的基础知识:P
答案 2 :(得分:1)
$result_string = "/usr/local/bin/casperjs test.js \"" . $proxy . "\" \"" . $button . "\" 2>&1";
或
$result_string = '/usr/local/bin/casperjs test.js "' . $proxy . '" "' . $button . '" 2>&1';