function checkStrHtml($string){ $string = trim_space($string); if(is_numeric($string)) return $string; if(!isset($string) or empty($string)) return ''; $string = preg_replace('/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]/','',$string); $string = ($string); $string = strip_tags($string,""); //清除HTML如<br />等代码 // $string = str_replace("\n", "", str_replace(" ", "", $string));//去掉空格和换行 $string = str_replace("\n", "", $string);//去掉空格和换行 $string = str_replace("\t","",$string); //去掉制表符号 $string = str_replace(PHP_EOL,"",$string); //去掉回车换行符号 $string = str_replace("\r","",$string); //去掉回车 $string = str_replace("'","‘",$string); //替换单引号 $string = str_replace("&","&",$string); $string = str_replace("=★","",$string); $string = str_replace("★=","",$string); $string = str_replace("★","",$string); $string = str_replace("☆","",$string); $string = str_replace("√","",$string); $string = str_replace("±","",$string); $string = str_replace("‖","",$string); $string = str_replace("×","",$string); $string = str_replace("∏","",$string); $string = str_replace("∷","",$string); $string = str_replace("⊥","",$string); $string = str_replace("∠","",$string); $string = str_replace("⊙","",$string); $string = str_replace("≈","",$string); $string = str_replace("≤","",$string); $string = str_replace("≥","",$string); $string = str_replace("∞","",$string); $string = str_replace("∵","",$string); $string = str_replace("♂","",$string); $string = str_replace("♀","",$string); $string = str_replace("°","",$string); $string = str_replace("¤","",$string); $string = str_replace("◎","",$string); $string = str_replace("◇","",$string); $string = str_replace("◆","",$string); $string = str_replace("→","",$string); $string = str_replace("←","",$string); $string = str_replace("↑","",$string); $string = str_replace("↓","",$string); $string = str_replace("▲","",$string); $string = str_replace("▼","",$string); // --过滤微信表情 $string = preg_replace_callback('/[\xf0-\xf7].{3}/', function($r) { return '';}, $string); return $string; }
function trim_space($str, $arr = array()) { if (empty($arr)) { $arr = array(' ', ' '); } foreach ($arr as $key => $val) { $str = preg_replace('/(^'.$val.')|('.$val.'$)/', '', $str); } return $str; }
本文为看恩吧原创文章,转载无需和我联系,但请注明来自knsay.com