简体   繁体   English

在html页面中显示html代码

[英]display html code in html page

Am using this following method to display html code in html page 我正在使用以下方法在html页面中显示html代码

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

Since my page are html so i can't run above method because its php 由于我的页面是html因此我无法运行上述方法,因为它的php

so i decide to use this following method based on only html 所以我决定只基于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;
            }

Problem is this method doesn't 问题是这种方法不

can some one help me how do i display codes on web pages 有人可以帮我如何在网页上显示代码吗

Ideas on how to display/present HTML tags on a webpage 关于如何在网页上显示/显示HTML标签的想法

Use the <xmp> tag instead of <pre> . 使用<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>

As "" tag is deprecated alternatively you can do like this: 由于不建议使用“”标签,因此您可以执行以下操作:

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

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

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

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