PHP methods for filtering ASCII control characters _php Tutorial

Source: Internet
Author: User
Tags control characters
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 = = $asc _code = = 13) {

$new _string. = ";

}

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

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

}

}

Return trim ($new _string);

}

http://www.bkjia.com/PHPjc/814671.html www.bkjia.com true http://www.bkjia.com/PHPjc/814671.html techarticle 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 to avoid ...

  • 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.