PHP htmlreplace Input Filter Security function Instance code

Source: Internet
Author: User
Htmlreplace is to replace the contents of all HTML files or selected HTML files in a directory with the contents of the specified file, which is especially useful for the same contents of a page, such as a menu bar.

This substitution function allows for some security filtering of user input, preventing users from committing unsafe code.

$rptype = 0 means replacing HTML tags only//$rptype = 1 means replacing HTML tags while removing contiguous whitespace characters//$rptype = 2 means replacing HTML tags while removing all whitespace characters//$rptype =-1 means only Replace the HTML dangerous tag function htmlreplace ($STR, $rptype =0) {$str = Stripslashes ($STR), if ($rptype ==0) {$str = Htmlspecialchars ($st R); } else if ($rptype ==1) {$str = Htmlspecialchars ($str); $str = Str_replace ("", "', $str); $str = Ereg_replace ("[Rnt]{1,}", ", $str); } else if ($rptype ==2) {$str = Htmlspecialchars ($str); $str = Str_replace ("", "', $str); $str = Ereg_replace ("[Rnt]", "', $str); } else {$str = Ereg_replace ("[Rnt]{1,}", "', $str); $str = eregi_replace (' script ', ' script ', $str); $str = Eregi_replace (" & Lt [/] {0,1} (LINK|META|IFR|FRA) [^>]*> ",", $str); } return Addslashes ($STR); }
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.