php下过滤HTML代码的函数

yipeiwu_com6年前PHP代码库

具体如下所示:

/*---------------------- 
过滤HTML代码的函数 
-----------------------*/ 
function htmlEncode($string) { 
  $string=trim($string); 
  $string=str_replace("&","&",$string); 
  $string=str_replace("'","'",$string); 
  $string=str_replace("&","&",$string); 
  $string=str_replace(""",""",$string); 
  $string=str_replace("\"",""",$string); 
  $string=str_replace("&lt;","<",$string); 
  $string=str_replace("<","<",$string); 
  $string=str_replace("&gt;",">",$string); 
  $string=str_replace(">",">",$string); 
  $string=str_replace("&nbsp;"," ",$string); 
  $string=nl2br($string); 
  return $string; 
} 

以上所述是小编给大家介绍的php下过滤HTML代码的函数,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对【宜配屋www.yipeiwu.com】网站的支持!

相关文章

php运行出现Call to undefined function curl_init()的解决方法

在网上下载了一个模拟登陆discuz论坛的php程序范例,试运行时出现“Call to undefined function curl_init”这个错误提示,没有定义的函数,也就是ph...

php 使用file_get_contents读取大文件的方法

当我们遇到文本文件体积很大时,比如超过几十M甚至几百M几G的大文件,用记事本或者其它编辑器打开往往不能成功,因为他们都需要把文件内容全部放到内存里面,这时就会发生内存溢出而打开错误,遇到...

php file_put_contents()功能函数(集成了fopen、fwrite、fclose)

命令:file_put_contents(); 命令解析:file_put_contents (PHP 5) file_put_contents -- 将一个字符串写入文件 说明: in...

PHP中去掉字符串首尾空格的方法

第一种方法:通过php自带的函数 <?php /* trim 去除一个字符串两端空格, rtrim 是去除一个字符串右部空格, ltrim 是去除一个字符串左部空格。 */ ?&g...

PHP 程序员也要学会使用“异常”

网站完全开放的特性,决定了网站比任何传统软件都更希望做到“系统看起来永远都是能够正常工作的”,所以采用正确的程序错误处理方式尤为重要。理论上来说,如果设计足够完美,开发人员足够谨慎,程序...