PHP uses Strip_tags () to remove HTML tags there are still blank solutions _php tips

Source: Internet
Author: User
Tags php programming php regular expression

The example in this article tells you that PHP still has a blank solution for using strip_tags () to remove HTML tags. Share to everyone for your reference, specific as follows:

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

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

Like what:

<p>
  Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhirong
</p>
<p>
  <br/>
</p>
<p>
  ALSDKJF;LASKJD;FLASJ;
</p>
<p>
  asdjfasjd;lkafsj;lfdkj
</p>
<p>
  Aksdjfl;ak
< /p>

Strip_tags () is processed and then changed to

  Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhirong





  ;


  ASDJFASJD;LKAFSJ;LFDKJ


  Aksdjfl;ak

This may not be what we want, and then use regular substitution to remove the blanks.

Final results:

Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhibin Zhang Zhirong

In addition: \s represents a white space character, \s represents a non-white-space character (note case, general case indicates the opposite meaning)

PS: Here again for you to provide 2 more practical regular tools for your reference:

JavaScript Regular expression online test tool:
Http://tools.jb51.net/regex/javascript

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

More interested in PHP related content readers can view the site topics: "PHP Regular Expression Usage summary", "PHP string (String) Usage summary", "PHP Array" Operation Techniques Encyclopedia, "PHP Mathematical Arithmetic Skills summary", "PHP Data structure and algorithm tutorial" , "PHP Programming Algorithm Summary", "PHP operation and operator usage Summary" and "PHP common database Operation skill Summary"

I hope this article will help you with the PHP program design.

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.