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 <b>bold</b>echo htmlentities($str);// 输出: a 'quote' is <b>bold</b>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》
优化站文章更新抓住这三点!网络建设是什么?网络建设基本流程有哪些?腾讯企业邮箱使用小知识?域名过期多久可以重新注册?域名一般都是在哪里注册?怎样注册一级域名 如何选取域名linux中使用boost.python调用c++动态库的方法免费、擒拿、思考:正确认识互联网大佬周鸿祎创业型企业网站建设要优化网站有哪些手段?