I still remember that at work, I imported data from other websites to xml. But you will encounter a problem: the web page will have asciII control characters. At first, I thought it was added by someone else to prevent collection. Then I found one and added it to the filtering list. Until I slowly discovered that they are all characters in the ascii table. Once you find the cause, it will be easy to solve.
Copy code The code is as follows:
/**
* 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 == 13){
$new_string .= ' ';
}
else if($asc_code > 31 && $asc_code != 127){
$new_string .= $string[$i];
}
}
return trim($new_string);
}
http://www.bkjia.com/PHPjc/770091.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/770091.htmlTechArticleI still remember that at work, I imported data from other websites to xml. But you will encounter a problem: the web page will have asciII control characters. At first I thought it was someone else trying to prevent picking...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn