Php character filtering method_php tutorial

Source: Internet
Author: User
Php character filtering method. * ** Character filtering ** $ santype1: removes HTML, XML, and PHP tags. * 2: removes HTML, XML, and PHP tags and converts characters to HTML entities, double quotation marks and single quotation marks ** 3 /**
* Character filtering
* $ Santype 1: remove HTML, XML, and PHP tags,
* 2: remove HTML, XML, and PHP tags, convert characters into HTML entities, encode double quotation marks and single quotation marks
* 3: remove tags in HTML, XML, and PHP. add a backslash (') double quotation mark (") backslash (\) NULL before a specified predefined character.
* 4: used to clear data retrieved from a database or HTML form (remove HTML, XML, and PHP tags)
* 6: add a backslash (') double quotation mark (") backslash (\) NULL before the 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 ('/<([^>] +)>/Els', "' <'. 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 );
}
}

From adamboy

Escape * character filtering * $ santype 1: removes HTML, XML, and PHP tags. * 2: removes HTML, XML, and PHP tags, and converts characters to HTML entities, encode double quotation marks and single quotation marks * 3...

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.