PHP using regular filter JS script code example _php tutorial

Source: Internet
Author: User
Tags preg
The matching rule cannot be used for "/."

Source code Example:

Copy the Code code as follows:

Header ("Content-type:text/html;charset=utf-8");
$str = '
Test PHP regular match out JS code test PHP regular match out JS code test PHP regular match out JS code test PHP regular match out JS code test PHP regular match out JS code test PHP regular match out JS code


Test PHP regular match the JS Code ';

$preg = "/ <> /I <\ script="">";
$newstr = Preg_replace ($preg, "", $str, 3); The fourth parameter, 3, replaces 3 times, the default is-1, replaces all
Echo $newstr;<\>

?>

http://www.bkjia.com/PHPjc/768139.html www.bkjia.com true http://www.bkjia.com/PHPjc/768139.html techarticle matching rules can not be used "/script.*\/script/i", because it does not match to the newline character, then the multi-line JS will not be matched off. To use "/script[\s\s]*?\/script/i". The inside? means as little as possible ...

  • 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.