PHPæ¸
é¤htmlãcssãjsæ ¼å¼å¹¶å»é¤ç©ºæ ¼çPHPå½æ°
01 function 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);
06 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);
07 if(is_array($string)&&!empty($string[0])){
08 if(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 }
16 return $string;
17 }
php å»é¤htmlæ ç¾ js å cssæ ·å¼
01 function 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 åæ°
16 return $content;
17 }
温馨提示:答案为网友推荐,仅供参考