PHP filters the ASCII control character method

Source: Internet
Author: User
Tags control characters

Remember that you used to work on other Web sites that you crawled into XML. But there is a problem: the page will have ASCII control characters. At first it was thought that someone else had joined in order to prevent the collection and then found one to add one to the filter table. Until slowly discovered, they were all characters in the ASCII list. Find out why, it's a good solution.

/**

* Filter control characters based on 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 = = $asc _code = = 13) {

$new _string. = ';

}

else if ($asc _code > && $asc _code!= 127) {

$new _string. = $string [$i];

}

}

Return trim ($new _string);

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.