为何在使用语法高亮显示器显示HTML时进行解释

时间:2015-02-26 11:12:30

标签: php html5 syntaxhighlighter

我想使用Alex Gorbatchev SyntaxHighlighter插件在我的HTML页面中显示一些PHP。

我的问题是某些代码是由浏览器解释的,因为我不想这样做 (只是想以纯文本形式发送)

可以在那里找到代码 http://codepen.io/hugsbrugs/pen/OPEyZZ

我试图摆脱的错误是:

Failed to load resource: the server responded with a status of 404 (Not Found)

感谢@spender,我结束了:

<pre class="brush: php">
    <?php
    $code = file_get_contents('FILE_PATH');
    echo htmlentities($code);
    ?>
</pre>

我希望我可以在PHP中使用HEREDOC而不是将我的代码存储在外部文件中,但考虑使用单引号和双引号,我无法实现它......

1 个答案:

答案 0 :(得分:1)

因此,您需要对内容进行HTML编码,以便浏览器不会将其解释为HTML。

http://php.net/htmlentities