PHP character filtering Method _php tutorial

Source: Internet
Author: User
/**
* Character filtering
* $santype 1: Stripped of HTML, XML, and PHP tags,
* 2: Peel HTML, XML, and PHP tags, convert characters to HTML entities, encode double quotes and single quotes
* 3: Strip HTML, XML, and PHP tags, add backslash single quotation mark (') Double quotation mark (') backslash (\) NULL before specified predefined character
* 4: Used to clean up data retrieved from a database or HTML form (stripped of HTML, XML, and PHP tags)
* 6: Add backslash single quotation mark (') double quote (') backslash (\) NULL before specified predefined character
*
* */

function sanitize ($var, $santype = 1, $allowable _tags = ") {
if ($santype = = 1) {return strip_tags ($var, $allowable _tags = ");}
ElseIf ($santype = = 2) {return htmlentities (Strip_tags ($var, $allowable _tags), ent_quotes, ' UTF-8 ');}
ElseIf ($santype = = 3) {
Return Addslashes (Strip_tags ($var, $allowable _tags));
}
ElseIf ($santype = = 4) {
Return Stripslashes (Preg_replace ('/< ([^>]+) >/es ', ' < '. sanitize (' \\1 ', 5). ' > ' ", Strip_tags ($var, $allowable _tags)));
}
ElseIf ($santype = = 5) {
Return preg_replace ('/\son\w+\s*=/is ', ', $var);
}
ElseIf ($santype = = 6) {
Return addslashes ($var);
}
}

Excerpted from Adamboy

http://www.bkjia.com/PHPjc/478337.html www.bkjia.com true http://www.bkjia.com/PHPjc/478337.html techarticle /** * Character filtering * $santype 1: Strip HTML, XML and PHP tags, * 2: Peel HTML, XML and PHP tags, convert characters to HTML entities, encode double quotes and single quotes * 3 ...

  • Related Article

    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.