如何打印PHP作为HTML文本

时间:2013-01-26 23:52:16

标签: php html printing

请问,如何将php打印为html文本?

例如:

我有这个php行

if(defined('LOAD_VARS') AND LOAD_VARS === TRUE)

我想将其打印为html文本

所以输出将是

if(defined('LOAD_VARS') AND LOAD_VARS === TRUE)

我试过这个

<textarea style="width:600px; height:30px;">if(defined('LOAD_VARS') AND LOAD_VARS === TRUE)</textarea>

但它不起作用并显示错误

我怎么能这样做?

如何

2 个答案:

答案 0 :(得分:4)

你的问题不是很清楚,但这里有:

在输出任何内容之前关闭PHP代码,或者只使用print()echo

示例1:

<?php
print('if(defined(\'LOAD_VARS\') AND LOAD_VARS === TRUE)');
?>

示例2

<?php
// Your code that you want to be run.
?>

<pre>if(defined('LOAD_VARS') AND LOAD_VARS === TRUE)</pre>

答案 1 :(得分:1)

查看highlight_string

$source = "if(defined('LOAD_VARS') AND LOAD_VARS === TRUE)";
echo highlight_string($source, true);