Using PHP strip_tags () to remove HTML tags still has a blank solution

Source: Internet
Author: User
This article mainly introduces PHP using Strip_tags () to remove HTML tags still have a blank solution, involving PHP regular replacement of the relevant operational skills, the need for friends can refer to the following

This article explains how PHP uses Strip_tags () to remove HTML tags and still have blank solutions. Share to everyone for your reference, as follows:

$subject = Strip_tags ($newsRs [' content ']);//Remove HTML tag $pattern = '/\s/';//Remove Blank $content = preg_replace ($pattern, ', $ subject);      $seodata [' articledescription '] = mb_substr ($content, 0, 80);//intercept 80 characters

Note: Strip_tags () in the first step; just replace the HTML tag with a space

Like what:

<p>  Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhijin </p><p>  <br/></p><p>  ALSDKJF;LASKJD;FLASJ ;</p><p>  asdjfasjd;lkafsj;lfdkj</p><p>  aksdjfl;ak</p>

Strip_tags () after processing becomes

  Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhijin alsdkjf;laskjd;flasj          ;      ASDJFASJD;LKAFSJ;LFDKJ      Aksdjfl;ak

This may not be what we want, and then we'll just remove the blanks with a regular replacement.

Final Result:

Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhijin Alsdkjf;laskjd;flasj;asdjfasjd;lkafsj;lfdkjaksdjfl;ak

In addition: \s denotes whitespace characters, \s denotes non-whitespace characters (note case, general case indicates the opposite meaning)

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

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.