trim-to remove whitespace characters (or other characters) at the end of a string
Usage:
String Trim (String $str [, String $charlist = "\t\n\r\0\x0b"])
Trim function Everyone should not be unfamiliar with the new optional charlist parameters from 4.1.0. The default usage is not much to say, say in the case of using the second parameter:
$path = Trim (dirname (__file__), '/'). ' /’; Guaranteed $path only one/end
There is no problem with this usage. What's going to go wrong? Another example:
$domain = Trim (' www.example.com.tw ', ' www. '); The expected result is example.com.tw, but the actual result is the EXAMPLE.COM.T,TW in the W.
The problem appears in the second parameter $charlist, which represents a list of characters rather than a simple string, so TW's w belongs to www. One of the members of this list was removed together. You can refer to the trim again
Alternate method:
$domain = Preg_replace ('/^www\.| www\.$/', ', ' www.example.com.tw ');