我有一个特殊的情况,我在一个数组中有一个不同的字符串范围。
我需要的是在/第三次出现时删除字符串的最后一部分。
的例子:
配件/男装配件/包包/钱包/邮差包/
这里我想删除:信使袋/
这是怎么可能的PHP -记住我有很多不同的字符串!所以我不能接受这个职位,因为每次都不一样。
//Here you will have 4 elements
$parts = explode ('/', $string);
//this will glue the first 3 elements
list ($first, $second, $third) = $parts;
//Here you can see the desired result
var_dump (implode ('/',array($first, $second, $third)));
输出string 'Accessories / Mens Accessories / Bags Wallets ' (length=46)