我想从php中检索一些输出,使用bash。到目前为止,我有这个:BASH从PHP获取结果
CODE="<?php chdir('$WWW');" # $WWW should be interpolated
CODE+=$(cat <<'PHP' # no interpolation for the rest of the code
require_once('./settings.php');
$db = $databases['default']['default'];
$out = [
'user=' . $db['username']
//more here
];
echo implode("\n", $out)
PHP)
echo $CODE
#RESULT=$($CODE | php)
#. $RESULT
总而言之,我有麻烦的字符串插值。现在我得到:
line 10: <?php: command not found
那么我该如何正确地逃避字符串,使整个PHP代码?
所有的一切,PHP应该产生输出这样的:
key=value
key2=value2
可以在未来
由于是“源”,由庆典!
这是更完整的答案,所以我会选择那个! – philipp