【问题标题】:display html code in html page在html页面中显示html代码
【发布时间】:2015-04-10 10:43:50
【问题描述】:

我正在使用以下方法在 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;
            }

问题是这个方法不行

谁能帮我在网页上显示代码

【问题讨论】:

  • 如果您将其转换为 .php。有什么问题?
  • @anantkumarsingh 但我如何在php 文件代码中显示 php 代码将被执行
  • 对不起,我不明白你的问题?你想在一个html文档中执行php代码吗?
  • @martin 我不想想执行php

标签: php html


【解决方案1】:

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

使用&lt;xmp&gt; 标签代替&lt;pre&gt;。

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

【讨论】:

  • 将所有出现的 和 >):
     <?php echo 'hello world'; ?> 
  • 在 php 中有没有其他方法可以做,或者我只能使用特殊代码
  • 在 php 中你可以使用函数 highlight_string()。 php.net/manual/en/function.highlight-string.php
【解决方案2】:

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

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

参考:http://www.htmlcodetutorial.com/_XMP.html

【讨论】:

  • 不,我不想使用特殊的 hrml 代码来执行此操作]
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-24
  • 1970-01-01
  • 2020-01-09
相关资源
最近更新 更多