trim()函数,可选字符串的疑问
程序员文章站
2022-04-13 21:59:17
...
$text = "\t\tThese are a few words :) ... ";
var_dump($text);
echo '----------------------------------';
echo '
var_dump($text);
echo '----------------------------------';
echo '
';
$trimmed = trim($text);
var_dump($trimmed);
$trimmed = trim($text, " \t:)");
var_dump($trimmed);
输出:
string 'These are a few words :) ...' (length=28)
string 'These are a few words :) ...' (length=28)
$trimmed = trim($text, " \t:).");
var_dump($trimmed);
输出:
string 'These are a few words' (length=21)
疑问是::)加了一个.后就能正常过滤了。为毛?
回复讨论(解决方案)
trim 的第二个参数是一个字符列表
凡是出现在该列表中的,第一个参数两端的字符都会被删去。在第一个不在列表中的字符处停止