PHP 5.4 - 当斜线作为第二个参数中的最后一个字符时,trim() 削减太多
PHP 5.4 - trim() cuts too much when slash as last character in the second argument
$string1 = "uploads/projects";
$string2 = "uploads/";
echo trim($string1, $string2); // outputs "rojects"
谁能告诉我为什么 trim()
函数输出 rojects
而不是 projects
字符串?
根据 trim
的 php 手册:
Optionally, the stripped characters can also be specified using the
character_mask parameter. Simply list all characters that you want
to be stripped. With .. you can specify a range of characters.
第二个参数表现为一组字符,而不是整个字符串。
因此出现在掩码参数 uploads
中的字符 p
将从 uploads/projects
字符串中删除。
也许你应该改用 str_replace
。
$string1 = "uploads/projects";
$string2 = "uploads/";
echo trim($string1, $string2); // outputs "rojects"
谁能告诉我为什么 trim()
函数输出 rojects
而不是 projects
字符串?
根据 trim
的 php 手册:
Optionally, the stripped characters can also be specified using the character_mask parameter. Simply list all characters that you want to be stripped. With .. you can specify a range of characters.
第二个参数表现为一组字符,而不是整个字符串。
因此出现在掩码参数 uploads
中的字符 p
将从 uploads/projects
字符串中删除。
也许你应该改用 str_replace
。