duanchi0897 2015-04-10 10:43
浏览 41
已采纳

在html页面中显示html代码

Am using this following method to display html code in html page

 <?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

so i decide to use this following method based on only 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

  • 写回答

2条回答 默认 最新

  • dongming8867 2015-04-10 10:47
    关注

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

    Use the <xmp> tag instead of <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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!