如何在PHP中显示htmlspecialchars

问题描述:

我如何使这个实际显示在PHP中?如何在PHP中显示htmlspecialchars

$answer=<script>alert(It converts to HTML.)</script> 
echo "The function is: htmlspecialchars ($answer)." 
+0

这是你的确切代码吗? – apokryfos

+0

我试图在页面上显示那个 – javalavamama

+0

您的预期输出是什么? – C2486

与您的问题相比更具克莱尔特色。你想用这个脚本怎么样?和什么是你的问题在PHP?

$answer = "<script>alert(It converts to HTML.)</script>" 
echo "The function is: htmlspecialchars (". $answer .")." //something like this? or htmlspecialchars is a php function? 
+0

我想让它显示我在网页上的问题上输入的具体内容 – javalavamama

+0

htmlspecialchars是php的一个函数吗? 检查我的编辑 –

$answer = "<script>alert(It converts to HTML.)</script>"

echo "The function is: htmlspecialchars".$answer;

$variable = <<<'EOS' 
$answer=<script>alert(It converts to HTML.)</script> 
echo "The function is: htmlspecialchars ($answer)." 
EOS; 
echo htmlspecialchars($variable); 

这将准确显示你输入的信息。

+0

这工作谢谢你! – javalavamama