Php uses strip_tags () to remove html tags.

Source: Internet
Author: User

Php uses strip_tags () to remove html tags.

The example in this article describes how php uses strip_tags () to remove html tags. We will share this with you for your reference. The details are as follows:

$ Subject = strip_tags ($ newsRs ['content']); // remove the html Tag $ pattern = '/\ s /'; // remove blank $ content = preg_replace ($ pattern, '', $ subject); $ seodata ['articledescription'] = mb_substr ($ content, 0, 80 ); // intercept 80 Chinese Characters

Note: in step 1, The strip_tags (); only replaces the html tag with spaces.

For example:

<P> Zhang zhibin </p> <br/> </p> <p> alsdkjf; laskjd; flasj; </p> <p> asdjfasjd; lkafsj; lfdkj </p> <p> aksdjfl; ak </p>

After strip_tags () is processed, it becomes

Zhang zhibin ZHANG Zhi alsdkjf; laskjd; flasj; asdjfasjd; lkafsj; lfdkj aksdjfl; ak

This may not be what we want. Then we can use the regular expression replacement to remove the blank space.

Final result:

Zhang zhibin ZHANG Zhi alsdkjf; laskjd; flasj; asdjfasjd; lkafsj; lfdkjaksdjfl; ak

In addition, \ s indicates white space characters, and \ S indicates non-white space characters (case sensitive, generally case sensitive indicates the opposite meaning)

PS: Here are two more practical Regular Expression tools for your reference:

JavaScript Regular Expression online testing tool:
Http://tools.jb51.net/regex/javascript

Regular Expression generation tool:
Http://tools.jb51.net/regex/create_reg

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.