在html页面中显示html代码

时间:2015-04-10 10:43:51

标签: php html

使用以下方法在html页面中显示html代码

 <?php $userSuppliedHTML = "<div>snaoj</div>"; ?>
 <code><?php echo htmlentities($userSuppliedHTML, ENT_QUOTES, 'UTF-8'); ?></code>    

由于我的网页为html,因此我无法在上述方法上运行,因为其php

所以我决定仅基于html

使用以下方法
        <blockquote>
            <pre>
             <code>
               <div>snaoj</div>
                My pre-formatted "quoted" code here.
              </code>
            </pre>
        </blockquote>

pre{
                font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;
                margin-bottom: 10px;
                overflow: auto;
                width: auto;
                padding: 5px;
                background-color: #eee;
                width: 650px;
                padding-bottom: 20px;
                max-height: 600px;
            }

问题是这个方法没有

有人可以帮助我如何在网页上显示代码

2 个答案:

答案 0 :(得分:2)

Ideas on how to display/present HTML tags on a webpage

使用<xmp>标记代替<pre>

<xmp>
<html>
<body>This is my html inside html.</body>
</html>
</xmp>

You can use highlight_string() php function to display php code

<?php
highlight_string('<?php phpinfo(); ?>');
?>

Replace all occurences of < with &lt; (and optionally > with &gt;):

<pre>
&lt;?php echo 'hello world'; ?&gt;
</pre>

答案 1 :(得分:0)

由于“”标签已被弃用,您可以这样做:

<PRE>
&#60;A HREF="http://www.idocs.com"&#62;Cool Dude&#60;/A&#62;
</PRE>

Reff:http://www.htmlcodetutorial.com/_XMP.html

相关问题