2010-11-25 59 views

回答

3

使用爆炸而不是拆分。爆炸的结果是一个数组,所以使用list()

list(,$productid) = explode('_', $PagePath, 2); 

注2代替1.使用1将不分裂的任何第三个参数,。或者,只是使用preg_replace

$productid = preg_replace('/^.*?_/', '', $PagePath); 
+0

谢谢:D完美地完成了这项工作,我到底是怎么忘记了正则表达式神太迟了 – user393273 2010-11-25 22:46:31

2

你可以尝试:

$productidtokens = explode("_",$pagePath, 2); 
if(count($productidtokens)>1) 
    $productid = $productidtokens[1]; 
0

尝试$productid = explode('_',$PagePath)

如果你只是想在'_'后面取文字,那就摆脱写出的数组中的第一个索引:array_shift($productid)

2

$ productId = substr($ string,(strpos($ PagePath,'_')+ 1)); // + 1占下划线