您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php怎么将字符串转为html

2025/3/27 10:24:05发布24次查看
php将字符串转为html的方法:可以利用htmlentities()函数来实现。该函数可以把字符转换为html实体,函数语法:【htmlentities(string,quotestyle,character-set)】。
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 &amp; 'adams'<br />john &amp; &#039;adams&#039;<br />john &amp; 'adams'</body></html>
以上就是php怎么将字符串转为html的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product