Regular expressions match html characters to filter illegal characters

Source: Internet
Author: User
Tags html tags regular expression

Match an html tag. The matching table is as follows:

<Table. *?> [Ss] * </table>
Or
<Table. *?> [Ss] *? </Table>

The above two expressions add "? "And one "? ", What is the difference?
We know "? "In a regular expression is a wildcard: matches the previous subexpression zero or once, or specifies a non-greedy qualifier.

Here, through testing, we come to the conclusion that "?" is not added "? When the following content is matched:

<Table> This is the first table. </table>
I am not the content in the table
<Table> This is the second table. </table>
I am not the content in the table either.
<Table> This is the third table. </table>

<?

$ Str = preg_replace ("/s +/", "", $ str); // filter excess carriage return
$ Str = preg_replace ("/<[] +/si", "<", $ str); // filter <__( "<" followed by a space)

$ Str = preg_replace ("/<! --.*? -->/Si "," ", $ str); // comment
$ Str = preg_replace ("/<(!. *?)> /Si "," ", $ str); // filter doctype
$ Str = preg_replace ("/<(/? Html. *?)> /Si "," ", $ str); // filter html tags
$ Str = preg_replace ("/<(/? Head. *?)> /Si "," ", $ str); // filter head tags
$ Str = preg_replace ("/<(/? Meta. *?)> /Si "," ", $ str); // filter meta Tags
$ Str = preg_replace ("/<(/? Body. *?)> /Si "," ", $ str); // filter the body tag
$ Str = preg_replace ("/<(/? Link. *?)> /Si "," ", $ str); // filter link tags
$ Str = preg_replace ("/<(/? Form. *?)> /Si "," ", $ str); // filter form labels
$ Str = preg_replace ("/cookie/si", "cookie", $ str); // filter cookie tags

$ Str = preg_replace ("/<(applet. *?)> (.*?) <(/Applet. *?)> /Si "," ", $ str); // filter the applet tag
$ Str = preg_replace ("/<(/? Applet. *?)> /Si "," ", $ str); // filter the applet tag

$ Str = preg_replace ("/<(style. *?)> (.*?) <(/Style. *?)> /Si "," ", $ str); // filter style labels
$ Str = preg_replace ("/<(/? Style. *?)> /Si "," ", $ str); // filter style labels

$ Str = preg_replace ("/<(title. *?)> (.*?) <(/Title. *?)> /Si "," ", $ str); // filter the title tag
$ Str = preg_replace ("/<(/? Title. *?)> /Si "," ", $ str); // filter the title tag

$ Str = preg_replace ("/<(object. *?)> (.*?) <(/Object. *?)> /Si "," ", $ str); // filter object tags
$ Str = preg_replace ("/<(/? Objec. *?)> /Si "," ", $ str); // filter object tags

$ Str = preg_replace ("/<(noframes. *?)> (.*?) <(/Noframes. *?)> /Si "," ", $ str); // filter noframes tags
$ Str = preg_replace ("/<(/? Noframes. *?)> /Si "," ", $ str); // filter noframes tags

$ Str = preg_replace ("/<(I? Frame. *?)> (.*?) <(/I? Frame. *?)> /Si "," ", $ str); // filter frame labels
$ Str = preg_replace ("/<(/? I? Frame. *?)> /Si "," ", $ str); // filter frame labels

$ Str = preg_replace ("/<(script. *?)> (.*?) <(/Script. *?)> /Si "," ", $ str); // filter script tags
$ Str = preg_replace ("/<(/? Script. *?)> /Si "," ", $ str); // filter script tags
$ Str = preg_replace ("/webpage effects/si", "javascript", $ str); // filter script tags
$ Str = preg_replace ("/vbscript/si", "vbscript", $ str); // filter script tags
$ Str = preg_replace ("/on ([a-z] +) s * =/si", "on \ 1 =", $ str); // filter script tags
$ Str = preg_replace ("// & #/si", "& #", $ str); // filter script tags, such as javascript: alert ('aabb)

?>

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.