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

function delhtmltags($string){$string = preg_replace("'([\r\n])[\s]+'", "", $string);               //去掉空白字符
        $string = preg_replace("'&(quot|#34);'i", "", $string);               //替换HTML实体
        $string = preg_replace("'&(amp|#38);'i", "", $string);
        $string = preg_replace("'&(lt|#60);'i", "<", $string);
        $string = preg_replace("'&(gt|#62);'i", ">", $string);
        $string = preg_replace("'&(nbsp|#160);'i", "", $string);
        $string = preg_replace("'<script[^>]*?>.*?</script>'si", "", $string);//去掉javascript
        $string = preg_replace("'<[\/\!]*?[^<>]*?>'si", "", $string);         //去掉HTML标记
        $string = preg_replace ('/ | /is', '', $string);                     //去掉多余空格

return $string; }

此方法能装在线文本编辑器里的所有格式清除,借鉴了大家的方法总结而成!

一直想做事,却止步于思考。
原文地址:https://www.cnblogs.com/betx/p/2744385.html