Php uses regular expression replacement to filter out js (script) script examples

Source: Internet
Author: User
Use the preg_replace regular expression matching function in php to filter out js code in the webpage. The fourth parameter in preg_replace () indicates the number of replicas. the default value is-1, indicating that all replicas are replaced; if you only want to replace it twice, you can write it as pre... use the preg_replace regular expression matching function in php to filter out js code in the webpage. The fourth parameter in preg_replace () indicates the number of replicas. the default value is-1, indicating that all replicas are replaced; if you only want to replace it twice, you can write it as preg_replace ($ p1, $ p2, $ p3, 2 ).

The matched rule cannot be used "/ <\ script> /I ", because it cannot match the line break, so multiple lines of js won't match. To use "/ <\ script> /I ". Inside? Indicates that there are as few duplicates as possible, that is, matching the latest script. <\> <\>

Source code example:

 Script test php regular expression matching js code

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.