trim()函数,可选字符串的疑点
时间:2021-07-01 10:21:17
帮助过:22人阅读
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 的第二个参数是一个字符列表
凡是出现在该列表中的,第一个参数两端的字符都会被删去。在第一个不在列表中的字符处停止