问题:
ABC-101-Description-text-1
ABC-2001-Description-text-with-more-text-2
ABC-20001-Some-more-Description-text-with-more-text-3
有没有人能帮我得到连字符第n次出现之前的所有文本,所以如果我想要ABC-20001在一个实例中,或者想要ABC-2001之后的所有内容。
我明白我需要使用strstr或strpos,但不确定,将感谢一些帮助…
如果您已经知道下面的n是整数:
$parts = explode('-',$string,$n);
我们取这个字符串:
$string = "ABC-20001-Some-more-Description-text-with-more-text-3";
如果你想要第二个连字符之前的内容:
$parts = explode('-',$string,$n+1); // n=2,
$parts[0] = 'ABC-20001';
$parts[1] = 'Some-more-Description-text-with-more-text-3';
第三个例子:http://uk1.php.net/manual/en/function.explode.php.