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中的常用魔术方法汇总

这篇文章详细的对php中的常用魔术方法进行了整理归纳,分享给大家供大家参考,具体内容如下 1、PHP把所有”__”开头的方法当做魔术方法,所以任何自定义的方法都不能是”__”开头 php...

php连接sftp的作用以及实例代码

sftp 协议 使用SSH协议进行FTP传输的协议叫SFTP(安全文件传输)Sftp和Ftp都是文件传输协议。 区别: sftp是ssh内含的协议(ssh是加密的telnet协议),只...

php通过数组实现多条件查询实现方法(字符串分割)

复制代码 代码如下:<?php $keyword="asp php,jsp"; $keyword=str_replace(" "," ",$keyword); $keyword=s...

PHP 高级课程笔记 面向对象

例一: 复制代码 代码如下:<?php // 类的定义 class User { // 属性,注意public、private、protected的作用范围 public $nam...

php根据生日计算年龄的方法

本文实例讲述了php根据生日计算年龄的方法。分享给大家供大家参考。具体如下: <?php function birthday($birthday){ $age =...