PHP Filters All HTML tags

Source: Internet
Author: User
Tags html tags

First we recommend filter_sanitize_string, filter_sanitize_string filter to remove or encode unwanted characters.

This filter deletes data that is potentially harmful to the application. It is used to remove labels and to delete or encode unwanted characters.

Name: "String"
id-number:513
Possible options or flags:

Filter_flag_no_encode_quotes-This flag does not encode quotes
Filter_flag_strip_low-Remove characters with ASCII value below 32
Filter_flag_strip_high-Removes ASCII values above 32 characters
Filter_flag_encode_low-characters encoded with ASCII values below 32
Filter_flag_encode_high-encoded ASCII values above 32 characters
Filter_flag_encode_amp-encode & characters as &

*/

$var = "<b>bill gates<b>";

Var_dump (Filter_var ($var, filter_sanitize_string));

/*
Second function strip_tags
The Strip_tags () function strips the tags of HTML, XML, and PHP tutorials.

Grammar
Strip_tags (String,allow)
*/

echo strip_tags ("Hello <b>world!</b>");

Hello world!

Function uh ($STR)
{
$farr = Array (
"/s+/",
Filter for extra whitespace
"/< (/?) (script|i?frame|style|html|body|title|link|meta|?|%) ([^>]*?) >/isu ",
Filtering <script can introduce malicious content or malicious changes to display the layout of the code, if you do not need to insert flash, and so on, but also
To join the <object filter
"/(<[^>]*) on[a-za-z]+s*= ([^>]*>)/isu",
On event to filter the web effects

);
$tarr = Array (
" ",
' <123> ',//If you want to clear the unsafe label directly, leave this blank
"12",
);

$str = Preg_replace ($farr, $tarr, $STR);
return $str;
}

For more details please see: http://www.111cn.net/phper/19/70dd2a905e74cefc9be9c0f17268dadc.htm
?>

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.