htmlentities() 函数把字符转换为 html 实体。
(推荐教程:php图文教程)
语法:
htmlentities(string,quotestyle,character-set)
实现代码:
<html><body><?php$str = "john & 'adams'";echo htmlentities($str, ent_compat);echo "<br />";echo htmlentities($str, ent_quotes);echo "<br />";echo htmlentities($str, ent_noquotes);?></body></html>
(视频教程推荐:php视频教程)
输出:
john & 'adams'john & 'adams'john & 'adams'
如果在浏览器中查看源代码,会看到这些 html:
<html><body>john & 'adams'<br />john & 'adams'<br />john & 'adams'</body></html>
以上就是php怎么将字符串转为html的详细内容。
