我想在文本区域显示一个代码片段,以便轻松剪切和粘贴,如何?

我想在文本区域显示一个代码片段,以便轻松剪切和粘贴,如何?

问题描述:

I am generating a bit of code to display a picture as a link (frex <a href="site.com"><img src="/image.gif"></a>) I would like to show how it look, but also in a textbox adjacent show the actual code. Is there a function in PHP that will automagically escape HTML code so it can be displayed?

我生成一些代码来将图片显示为链接(frex &lt; a href = “site.com”&gt;&lt; img src =“/ image.gif”&gt;&lt; / a&gt; code>)我想展示它的外观,还可以在相邻的文本框中显示实际代码。 PHP中是否有一个函数可以自动转义HTML代码以便显示它? p> div>

print "<textarea>" . htmlspecialchars($html) . "</textarea>";

Here you can find details about htmlspecialchars from official documentation.