In rich text, how does one obtain plain text by filtering conditions?

Source: Internet
Author: User
For example, if a long article containing html tags obtains 400 characters of text, the filter conditions are as follows: hyperlink, & amp; lt; code & amp; gt; tag, bold label and italic label. The remaining labels only contain plain text. Delete linefeeds and img tags. Replace two or more spaces with one .... For example, if a long article containing html tags obtains 400 characters of text, the filter conditions are as follows: Hyperlink, Tag,Bold labels,Italic label.
The remaining labels only contain plain text.
Delete linefeeds and img tags. Replace two or more spaces with one.
Within 400 characters, if, Bold, italic labels are not closed to filter the remaining content.
If the hyperlink is not closed within 400 characters, wait until the hyperlink is closed.
Many examples found online do not match. So I asked a question on sf. Do not delete the problem. Hope competent programmers can help.

Reply content:

For example, if a long article containing html tags obtains 400 characters of text, the filter conditions are as follows:Hyperlink,Tag,Bold labels,Italic label.
The remaining labels only contain plain text.
Delete linefeeds and img tags. Replace two or more spaces with one.
Within 400 characters, if, Bold, italic labels are not closed to filter the remaining content.
If the hyperlink is not closed within 400 characters, wait until the hyperlink is closed.
Many examples found online do not match. So I asked a question on sf. Do not delete the problem. Hope competent programmers can help.

In the visual test, you need to replace the regular expression based on the matching conditions.
We recommend that you first read the regular expression tutorial and split the requirement into multiple steps.

Update:

In addition to string processing, it can also be understood as DOM processing. It is more appropriate to use JavaScript to process DOM.

I have used the simple_html_dom library before and can operate html like jquery. I hope it will be useful to you.

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.