还记得以前在工作中,将爬来的其它网站的数据导到xml。但是会遇到一个问题:即网页会有ascII的控制字符。一开始以为是别人为了防止采集而加入的,然后发现一个就往过滤表里加一个。直到慢慢发现,他们都是ascii表里的字符。找到原因了,就好解决了。
/**
* 根据ascii码过滤控制字符
* @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]); //得到其asc码
//以下代码旨在过滤非法字符
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);
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version
God-level code editing software (SublimeText3)
