How to convert & characters to HTML characters?

不羁的心 提交于 2019-12-06 02:51:48

You need one of these:

html_entity_decode()
htmlspecialchars_decode()

The main difference is that html_entity_decode() will translate all the HTML entities in your string (&lt; becomes <, &aacute; becomes á, etc.) while html_specialchars_decode() only translates some special HTML entities:

The converted entities are: &amp;, &quot; (when ENT_NOQUOTES is not set), &#039; (when ENT_QUOTES is set), &lt; and &gt;.

Are you looking for html_entity_decode?

If you're actually trying to do this manually, instead of with html_entity_decode, try str_replace.

$needle = array("&lt;","&gt;");
$replace = array("<", ">");
$string = '&lt;?php echo "Hello World!"; ?&gt;';

$string = str_replace($needle, $replace, $string);

print $string; // prints <?php echo "Hello World!"; ?>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!