Home > Article > Backend Development > PHP清除html、css、js格式并去除空格的PHP函数
function cutstr_html($string,$length=0,$ellipsis='…'){<br /> $string=strip_tags($string);<br /> $string=preg_replace('/\n/is','',$string);<br /> $string=preg_replace('/ | /is','',$string);<br /> $string=preg_replace('/ /is','',$string);<br /> preg_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);<br /> if(is_array($string)&&!empty($string[0])){<br /> if(is_numeric($length)&&$length){<br /> $string=join('',array_slice($string[0],0,$length)).$ellipsis;<br /> }else{<br /> $string=implode('',$string[0]);<br /> }<br /> }else{<br /> $string='';<br /> }<br /> return $string;<br />}