【问题标题】:why is HTML interpreted while displaying it with syntax highlighter为什么在使用语法高亮显示时解释 HTML
【发布时间】:2015-02-26 11:12:29
【问题描述】:

我想使用 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,而不是将我的代码存储在外部文件中,但考虑到使用单引号和双引号,我无法实现它......

【问题讨论】:

标签: php html syntaxhighlighter


【解决方案1】:

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

http://php.net/htmlentities

【讨论】:

    猜你喜欢
    • 2012-02-11
    • 1970-01-01
    • 2015-09-28
    • 2020-11-08
    • 1970-01-01
    • 2011-03-20
    • 1970-01-01
    • 2010-11-26
    • 2016-06-09
    相关资源
    最近更新 更多