Php filters all blank characters (spaces, full-angle spaces, line breaks, etc.), full-angle line breaks _ PHP Tutorial

Source: Internet
Author: User
Php filters all blank characters (spaces, full-angle spaces, line breaks, and so on), with full-angle line breaks. Php filters all blank characters (spaces, full-angle spaces, line breaks, etc.). the trim function that comes with full-angle line breaks in php can only replace spaces at both ends of the left and right, in some cases, php does not filter all blank characters (spaces, full-angle spaces, line breaks, etc.), and the full-angle line breaks

The self-contained trim function in php can only replace spaces on both sides of the left and right. in some cases, it may not be easy to use, if you want to filter out all the spaces (spaces, full-width spaces, line breaks, etc.) in a string, you can write a filter function by yourself.

Php learns str_replace functions and can be replaced in batches. Therefore, we can use the following source code to replace and filter all the blank characters in a string.

<? Php $ str = 'jkgsdgsgsdgs gsdg gsd'; echo myTrim ($ str); function myTrim ($ str) {$ search = array ("", "", "\ n ", "\ r", "\ t"); $ replace = array ("", ""); return str_replace ($ search, $ replace, $ str) ;}?>

Run the code and the page output: jkgsdgsgsdgsgsdggsd, which perfectly achieves the desired effect.

The above is the php method for filtering all the blank characters. I hope it will be helpful for your learning.

Trim (space, FULLWIDTH space, line feed, etc.). the trim function that comes with the full-width line feed in php can only replace the spaces on both sides of the left and right. in some cases, it is not very good...

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.