如何使用PHP回显html标记

如何使用PHP回显html标记,php,echo,Php,Echo,我想在屏幕上打印HTML标签。我不知道如何避开HTML标记 预期产出 <div>Hey, you can see the div tag on the screen.</div> 嘿,你可以在屏幕上看到div标签。 div标记不应作为HTML标记接收,而是我想在屏幕上打印它们。我该怎么做?echo htmlspecialchars('嘿,你可以在屏幕上看到div标签'); echo htmlspecialchars('<div>Hey, you can s

我想在屏幕上打印HTML标签。我不知道如何避开HTML标记

预期产出

<div>Hey, you can see the div tag on the screen.</div>
嘿,你可以在屏幕上看到div标签。
div
标记不应作为HTML标记接收,而是我想在屏幕上打印它们。我该怎么做?

echo htmlspecialchars('嘿,你可以在屏幕上看到div标签');
echo htmlspecialchars('<div>Hey, you can see the div tag on the screen.</div>');
您可以使用或

echo htmlentities('嘿,你可以在屏幕上看到div标签');
echo htmlspecialchars(‘嘿,你可以在屏幕上看到div标签’);
如图所示,您可以使用该功能

echo htmlspecialchars('<div>Hey, you can see the div tag on the screen.</div>');
echo htmlspecialchars('嘿,你可以在屏幕上看到div标签');

您也可以使用
strtr()
来完成此操作



你的意思是
回声“bla bla”
?@判决否,如果我这样做,我将无法看到“bla bla”。相反,我将只看到“bla-bla”。是的,您想要的是转义HTML标记。看见此外,您不需要手动执行此操作-如答案探索中所建议的。您可以执行此div bla bla&frasl;谢谢,我不知道这个函数。@NavneetSaini,这就是为什么你至少应该引用或
echo htmlspecialchars('<div>Hey, you can see the div tag on the screen.</div>');
    <?php   
    $input =  '<div>Hey, you can see the div tag on the screen.</div>';
    $output = strtr($input, Array("<" => "&lt;"));
print $output;
    ?>