trim (ltrim) 削减更多
trim (ltrim) cuts more
我有很多产品名称和品牌。一些产品名称包含品牌。有些没有。
我想删除产品名称中的品牌。
substr($name,strlen($brand));
导致无品牌名称出现问题。
然后我使用这个代码。但又出问题了。
$brand = "Palm See";
$name = "Palm See Second Third ... ";
$name = "See Season ... ";
$name = " See Sean Paul ";
$name = ltrim($name, $brand);
echo $name; // cond Third ... desired : Second Third ...
echo $name; // son ... desired : See Season ...
echo $name; // n Paul desired : See Sean Paul
再看看 ltrim
的工作原理:
character_mask
You can also specify the characters you want to strip, by means of the character_mask parameter. Simply list all characters that you want
to be stripped. With .. you can specify a range of characters.
尝试使用 str_replace
将其删除,仅使用 trim 删除任何多余的空格。
我有很多产品名称和品牌。一些产品名称包含品牌。有些没有。
我想删除产品名称中的品牌。
substr($name,strlen($brand));
导致无品牌名称出现问题。
然后我使用这个代码。但又出问题了。
$brand = "Palm See";
$name = "Palm See Second Third ... ";
$name = "See Season ... ";
$name = " See Sean Paul ";
$name = ltrim($name, $brand);
echo $name; // cond Third ... desired : Second Third ...
echo $name; // son ... desired : See Season ...
echo $name; // n Paul desired : See Sean Paul
再看看 ltrim
的工作原理:
character_mask
You can also specify the characters you want to strip, by means of the character_mask parameter. Simply list all characters that you want to be stripped. With .. you can specify a range of characters.
尝试使用 str_replace
将其删除,仅使用 trim 删除任何多余的空格。