The trim function is used to delete cells, but we must pay attention to it when using it. Let's introduce some problems and bugs in the space deletion of the trim function. The trim function is used to delete cells, but we must pay attention to it when using it. Let's introduce some problems and bugs in the space deletion of the trim function.
Script ec (2); script
Trim-removes spaces (or other characters) at the beginning and end of the string)
Usage:
String trim (string $ str [, string $ charlist = "\ t \ n \ r \ 0 \ x0B"])
You should be familiar with the trim function. The optional charlist parameter is added from 4.1.0. The default usage is not too much. Let's talk about the use of the second parameter:
$ Path = trim (dirname (_ FILE _), '/'). '/'; // ensure that $ path has only one/end
There is no problem with this usage. Under what circumstances will the problem occur? Another example:
$ Domain = trim ('www .example.com.tw ', 'www.'); // The expected result is example.com.tw, but the actual result is example.com. t. w in tw is gone.
The problem occurs in the second parameter $ charlist, which represents a character list rather than a simple string. Therefore, w of tw belongs to www. A member in this list is removed together. For more information, see trim.
Alternative method:
$ Domain = preg_replace ('/^ www \. | www \. $/', ", 'www .example.com.tw ');