简体   繁体   English

用代码标签突出显示HTML中的PHP代码-错误?

[英]Highlight PHP code in HTML with code tag - bug?

I'm using highlight.js to highlight the following code: 我正在使用Highlight.js突出显示以下代码:

<pre><code class="hljs php">
echo '<table border="1">';
echo '<tr>';
    foreach ($keys as &$k)
    {
    echo '<th>'.$k.'</th>';
    }
 echo '</tr>';
echo '</table>'
</code></pre>

AAAnd all the table tags are rendered by the browser and not displayed as clear text... see for yourself(jsfiddle without highlight.js) AA,所有表格标签均由浏览器呈现,并且不会以明文形式显示... 亲自查看(jsfiddle没有highlight.js)

Is it me oris there something wrong with the code tags? 是我还是代码标签有问题? Any Ideas? 有任何想法吗? Thank you 谢谢

Your tags: 您的标签:

<pre><code bla bla> must end </pre></code>

Final 最后

<pre><code bla bla> must end </code></pre>

EDIT: Answer in the comments: 编辑:在评论中回答:

<pre>
    <code class="hljs php">
        &lt;table&gt;
            &lt;tr&gt;
                &lt;th&gt;1&lt;/th&gt;
                &lt;th&gt;2&lt;/th&gt;
                &lt;th&gt;3&lt;/th&gt;
                &lt;th&gt;4&lt;/th&gt;
                &lt;th&gt;5&lt;/th&gt;
            &lt;/tr&gt;
        &lt;/table&gt;
    </code>
</pre>

Its nessecsary to HTML Escape the '<' and the '>'. 它对于HTML的必要性转义“ <”和“>”。 This can be achieved with this php Function 这可以通过此php函数实现

为什么不只使用HTML5标签?

<mark>Text here</mark>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM