Regular Expression-How php regular expressions match "<", ">" symbols of non-html tags

Source: Internet
Author: User
You need to escape the angle brackets in a piece of text, but some HTML labels need to be left, such as & amp; lt; br & amp; gt; & amp; lt; p & amp; how do I write an extensible regular expression? For example, you only need to exclude & amp; lt; br & amp; gt; & amp; lt; p & amp; gt ;, if you need to exclude one more HTML Tag directly on pattern, more... you need to escape the angle brackets in a piece of text, but some HTML labels need to be left, such

And so on. How do I write an extensible regular expression? For example, you only need to exclude

If you want to exclude one more HTML Tag, add one more group to the pattern tag? (The text is messy and cannot be parsed using HTML)
Find ]+>It seems wrong.
Or are there recommended functions or methods?

Reply content:

You need to escape the angle brackets in a piece of text, but some HTML labels need to be left, such

And so on. How do I write an extensible regular expression? For example, you only need to exclude

If you want to exclude one more HTML Tag, add one more group to the pattern tag? (The text is messy and cannot be parsed using HTML)
Find ]+>It seems wrong.
Or are there recommended functions or methods?

Preg_replace ("/<(br | p) \/?)> /I "," & l t; $1 & g t; ", $ str );

You can use the strip_tags function provided by php.
Http://php.net/manual/zh/function.strip-tags.php

<(?! Br | p). *?>
This may be the meaning. If it is pure, it is troublesome. You can write a program to process it.

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.