PHP Clear HTML Hyperlink/js script/carriage return _php Tutorial

Source: Internet
Author: User
In PHP to filter some special characters or illegal characters we can have a lot of ways, like the regular expression str_replace is a good way, like a carriage return, space, line can be used to solve.

The nearly responsible system module is finally close to the end, the rest of the work is to match the testing and modification of the test.

While this relatively idle time, secretly write a few blog posts to record the time of the problem and my solution (or say the solution to it).

Well, the nonsense is not much to say, get into the chase.

There is a general need to go to the thief program, such as the removal of the original page link or something. However, I encountered is to export the development of the page to Word, security needs to remove the JS code block.

First on the code

The code is as follows Copy Code

$searchRegex = Array (
'/(s*.*?s*)/I ',//Hyperlink
'//i ',//JS script code
);
$REPLACESTR = Array (
' $ ',
''
);
$content = Preg_replace ($searchRegex, $REPLACESTR, $content);


PHP words This is relatively simple, is the use of preg_replace this function, not much to say ... It is important to note that there are two regular bars.

The code is as follows Copy Code

$regexForLink = '/(s*.*?s*)/I '; Hypertext links
$regexForJS = '//i '; JS script code

If you want to filter HTML code, spaces, carriage return line breaks

The code is as follows Copy Code


function deletehtml ($STR)
{
$str = Trim ($STR);
$str = Strip_tags ($str, "");
$str = ereg_replace ("T", "", $str);
$str = ereg_replace ("rn", "", $str);
$str = Ereg_replace ("R", "", $str);
$str = Ereg_replace ("n", "", $str);
$str = Ereg_replace ("", "" ", $str);
Return trim ($STR);
}


Filtering all HTML tags in HTML can use the Strip_tags () function to strip HTML, XML, and PHP tags.

Strip_tags (String,allow)

Well, that's all, I hope it helps next time.

http://www.bkjia.com/PHPjc/633113.html www.bkjia.com true http://www.bkjia.com/PHPjc/633113.html techarticle in PHP to filter some special characters or illegal characters we can have a lot of ways, like the regular expression str_replace is a good way, like a carriage return, space, line can be used it ...

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