Home >Backend Development >PHP Tutorial >trim()函数,可选字符串的疑点
trim()函数,可选字符串的疑问 ';
$text = "\t\tThese are a few words :) ... ";
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 的第二个参数是一个字符列表
凡是出现在该列表中的,第一个参数两端的字符都会被删去。在第一个不在列表中的字符处停止