PHP删除HTMl标签的实现代码

yipeiwu_com5年前PHP代码库
复制代码 代码如下:

/**
 * 取出html标签
 *
 * @access public
 * @param string str
 * @return string
 *
 */
function deletehtml($str) {
    $str = trim($str); //清除字符串两边的空格
    $str = strip_tags($str,"<p>"); //利用php自带的函数清除html格式。保留P标签
    $str = preg_replace("/\t/","",$str); //使用正则表达式匹配需要替换的内容,如:空格,换行,并将替换为空。
    $str = preg_replace("/\r\n/","",$str);
    $str = preg_replace("/\r/","",$str);
    $str = preg_replace("/\n/","",$str);
    $str = preg_replace("/ /","",$str);
    $str = preg_replace("/  /","",$str);  //匹配html中的空格
    return trim($str); //返回字符串
}

相关文章

PHP中array_slice函数用法实例详解

本文详细介绍了array_slice函数的详细用法以及一些常用的array_slice实例程序,分享给大家供大家参考。具体分析如下: array_slice() 函数在数组中根据条件取出...

php对文件夹进行相关操作(遍历、计算大小)

为大家分享的第一个操作内容: 遍历并打印指定目录下所有文件 <?php //功能:遍历并打印指定目录下所有文件 function scan_dir(...

php error_log 函数的使用

我们来大致了解一下error_log()函数。我们看下手册的解释: error_log(PHP 3, PHP 4, PHP 5) bool error_log ( string mess...

php使用curl出现Expect:100-continue解决方法

本文实例讲述了php使用curl出现Expect:100-continue解决方法。分享给大家供大家参考。具体如下: 使用curl POST数据时,如果POST的数据大于1024字节,c...

PHP全局变量与超级全局变量区别分析

本文分析了PHP全局变量与超级全局变量区别。分享给大家供大家参考,具体如下: 全局变量就是在函数外面定义的变量。不能在函数中直接使用。因为它的作用域不会到函数内部。所以在函数内部使用的时...