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

PHP如何转义HTML字符?

2024/4/13 2:12:26发布11次查看
php如何转义html字符?
在php中可以通过使用“htmlentities()”函数转义html字符,该函数的作用是将字符转换为html转义字符,使用方法只需将html传入该函数,其返回值是转义后的html字符。
语法
htmlentities ( string $string [, int $flags = ent_compat | ent_html401 [, string $encoding = ini_get("default_charset") [, bool $double_encode = true ]]] ) : string
使用示例
<?php$str = "a 'quote' is <b>bold</b>";// 输出: a 'quote' is &lt;b&gt;bold&lt;/b&gt;echo htmlentities($str);// 输出: a &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;echo htmlentities($str, ent_quotes);?>
<?php$str = "\x8f!!!";// 输出空 stringecho htmlentities($str, ent_quotes, "utf-8");// 输出 "!!!"echo htmlentities($str, ent_quotes | ent_ignore, "utf-8");?>
推荐教程:《php》
以上就是php如何转义html字符?的详细内容。
该用户其它信息

VIP推荐

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