我需要在网页上显示一个没有任何格式的bash脚本。
当我尝试使用PHP heredoc函数输出脚本时,它在遇到'<<‘子字符串时切断了输出。
如何正确输出此脚本?
<?php
$string = $_GET["string"];
$bashscript = <<<MYMARKER
<pre>
#!/bin/sh
rm /tmp/blue.sh
cat <<INSTALL > /tmp/blue.sh
#!/bin/sh
cd /tmp
mkdir output
cd output
cat <<EOF > interface.conf
remote $string
EOF
INSTALL
</pre>
MYMARKER;
echo $bashscript;
?>我在页面上得到的输出是
#!/bin/sh
rm /tmp/blue.sh
cat < /tmp/blue.sh
#!/bin/sh
cd /tmp
mkdir output
cd output
cat < interface.conf
remote
EOF
INSTALL发布于 2013-02-20 00:23:58
这是因为<INSTALL >和<EOF >在您的浏览器中被解释为标签(尽管无法识别)。用鼠标右键打开->查看源码,你就会看到它。只需移出<pre>并使用htmlspecialchars()正确显示它:
$bashscript = <<<MYMARKER
... everything without the <pre> tags ...
MYMARKER;
echo '<pre>'.htmlspecialchars($bashscript).'</pre>';https://stackoverflow.com/questions/14962213
复制相似问题