php下过滤HTML代码的函数

yipeiwu_com5年前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的urlencode()URL编码函数浅析

URLEncode的方式一般有两种,一种是传统的基于GB2312的Encode(Baidu、Yisou等使用),另一种是基于UTF-8的Encode(Google、Yahoo等使用)。...

php设计模式 Mediator (中介者模式)

复制代码 代码如下: <?php /** * 中介者模式 * * 用一个中介对象来封装一系列的对象交互,使各对象不需要显式地相互引用从而使其耦合松散,而且可以独立地改变它们之间的交...

array_multisort实现PHP多维数组排序示例讲解

array_multisort — 对多个数组或多维数组进行排序 说明 bool array_multisort ( array ar1 [, mixed arg [, mixed .....

php简单实现多语言切换的方法

本文实例讲述了php简单实现多语言切换的方法。分享给大家供大家参考,具体如下: 1.主程序代码: <?php include "lib/function.php"; &...

PHP 获取文件路径(灵活应用__FILE__)

__FILE__ ,是返回文件的完整路径和文件名。如果用在包含文件中,则返回包含文件名。自 PHP 4.0.2 起,__FILE__ 总是包含一个绝对路径,而在此之前的版本有时会包含一个...