Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP不反映所需的HTML_Php_Html_Css - Fatal编程技术网

PHP不反映所需的HTML

PHP不反映所需的HTML,php,html,css,Php,Html,Css,我正在制作一个网站,用户应该能够在他们的个人资料中使用HTML和CSS,但我遇到了一个问题 <?php $profile = "<h1>THIS IS A TEST</h1>"; echo htmlentities($profile); ?> 这是我的代码,但它仅在配置文件中显示: 这是一个测试& 我不知道发生了什么,也不知道这是否只发生在我身上 如何使其仅显示h1内容?您只需使用echo$profile,仅此而已。

我正在制作一个网站,用户应该能够在他们的个人资料中使用HTML和CSS,但我遇到了一个问题

    <?php
    $profile = "<h1>THIS IS A TEST</h1>";
    echo htmlentities($profile);
    ?>

这是我的代码,但它仅在配置文件中显示:
这是一个测试&

我不知道发生了什么,也不知道这是否只发生在我身上


如何使其仅显示h1内容?

您只需使用
echo$profile,仅此而已。检查并不要忘记检查是否显示为HTML,因为浏览器将PHP回显文本显示为HTML,除非他们被告知以不同的方式显示。

函数
htmlentities
显示HTML字符的表示形式,如标记等,尤其用于避免解析为HTML。因此,如果您想回显html以便浏览器将其解析为html,那么您最不希望的就是使用此函数!只需直接回显,无需使用
htmlspecialchars
htmlspecialchars

谢谢,我从来没有想过自己会尝试这个:)