php如何清除html格式并去除文字中的空格然后截取文字

html-css012

php如何清除html格式并去除文字中的空格然后截取文字,第1张

PHP清除html、css、js格式并去除空格的PHP函数

01function cutstr_html($string,$length=0,$ellipsis='…'){

02$string=strip_tags($string)

03$string=preg_replace('/\n/is','',$string)

04$string=preg_replace('/ | /is','',$string)

05$string=preg_replace('/ /is','',$string)

06preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/",$string,$string)

07if(is_array($string)&&!empty($string[0])){

08if(is_numeric($length)&&$length){

09$string=join('',array_slice($string[0],0,$length)).$ellipsis

10}else{

11$string=implode('',$string[0])

12}

13}else{

14$string=''

15}

16return $string

17}

php 去除html标签 js 和 css样式

01function clearHtml($content){

02$content=preg_replace("/<a[^>]*>/i","",$content)

03$content=preg_replace("/<\/a>/i","",$content)

04$content=preg_replace("/<div[^>]*>/i","",$content)

05$content=preg_replace("/<\/div>/i","",$content)

06$content=preg_replace("/<!--[^>]*-->/i","",$content)//注释内容

07$content=preg_replace("/style=.+?['|\"]/i",'',$content)//去除样式

08$content=preg_replace("/class=.+?['|\"]/i",'',$content)//去除样式

09$content=preg_replace("/id=.+?['|\"]/i",'',$content)//去除样式

10$content=preg_replace("/lang=.+?['|\"]/i",'',$content)//去除样式

11$content=preg_replace("/width=.+?['|\"]/i",'',$content)//去除样式

12$content=preg_replace("/height=.+?['|\"]/i",'',$content)//去除样式

13$content=preg_replace("/border=.+?['|\"]/i",'',$content)//去除样式

14$content=preg_replace("/face=.+?['|\"]/i",'',$content)//去除样式

15$content=preg_replace("/face=.+?['|\"]/",'',$content)//去除样式 只允许小写 正则匹配没有带 i 参数

16return $content

17}

去除html内的cssjsphp首先我们需要打开这样的一个程序平台主页面,在这个程序群台主页面中,我们给他选择这样的一个去除html内的cssjsphp要这样的一个去除模式,我们就可以将他的一个程序完全的去除掉,就可以这样的一个设置流程步骤