PHP删除HTMl标签的实现代码
代码如下:
/** * 取出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); //返回字符串 }
相关推荐
stulen 2020-08-15
fengzhiwu 2020-08-01
liusarazhang 2020-06-28
xiaobaif 2020-06-14
lemonzhangyan 2020-06-13
Crazyshark 2020-06-13
weikaixxxxxx 2020-06-13
有梦就能实现 2020-06-10
shengnanonly 2020-06-03
oraclemch 2020-05-30
poplpsure 2020-05-27
fujuan000 2020-04-30
zuihaobushi 2020-04-30
luckymaoyy 2020-04-29
xiaoseyihe 2020-04-28
JackLang 2020-04-25
菇星獨行 2020-04-20
jyj00 2020-03-26