Explanation of deleting nbsp spaces using the phptrim function

Source: Internet
Author: User
In php, the trim function is used to delete spaces in strings rather than html code nbsp spaces. can we use trim to delete them? in fact, let's take a look at it. the nbsp mentioned here is an entity, not a four-character nbsp... in php, the trim function is used to delete spaces in strings rather than html code nbsp spaces. can we use trim to delete them? in fact, let's take a look at it.

The nbsp mentioned here is an entity rather than a four-character nbsp. the code is as follows:

$ Str = "abc"; $ converted = strtr ($ str, array_flip (get_html_translation_table (HTML_ENTITIES, ENT_QUOTES); var_dump ($ converted ); // Here is the string to be processed. the above are all preparations

When dealing with this problem, I experienced some twists and turns, first var_dump, but it is no different from the normal string. then I tried to output it using escape and found it was xa0, so I want to trim ($ converted, "xa0"), fruitless.

Finally, the solution was found in the first comment under the trim function in the php Manual. the code is as follows:

Var_dump (trim ($ converted, chr (0xc2). chr (0xa0 )));

In fact, to delete the strings, we don't need to be so complicated at all. we only need to use str_replace (). The code is as follows:

$ A = "www.phprm.com"; echo str_replace ('','', $ a); // The result is // www.phprm.com



Article URL:

Reprint ^ at will, but please attach the tutorial address.

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.