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.