Remember the data from other Web sites that were crawled to XML in the past at work. However, there is a problem: The Web page will have ASCII control characters. At first I thought it was someone else who joined in order to prevent the collection, and then found one on the filter table plus one. Until they are found, they are all characters in the ASCII table. Find out the reason, it is good to solve.
/** * Filter control characters according to ASCII code * @param type $string */public static function Special_filter ($string) { if (!$ string) return '; $new _string = "; for ($i =0; Isset ($string [$i]), $i + +) { $asc _code = Ord ($string [$i]);//get its ASC code //The following code is designed to filter illegal characters if ($ Asc_code = = 9 | | $ASC _code = = 10 | | $ASC _code = =) { $new _string. = '; } else if ($asc _code > && $asc _code! = 127) { $new _string. = $string [$i]; } } Return trim ($new _string); }
PHP Filter ASCII control characters