Reputation: 1438
basically i just want to get all the text after the _ .
i have tried
$productid = split("_",$PagePath, 1);
with no success what is the correct way of doing this?
Upvotes: 0
Views: 425
Reputation: 4769
You could try:
$productidtokens = explode("_",$pagePath, 2);
if(count($productidtokens)>1)
$productid = $productidtokens[1];
Upvotes: 2
Reputation: 72
$productId = substr($string, (strpos($PagePath, '_') + 1)); //+1 accounts for the underscore
Upvotes: 1
Reputation: 342
Try $productid = explode('_',$PagePath)
.
If you just intended to take the text after the '_', then get rid the first index in the array created by write : array_shift($productid)
.
Upvotes: 0
Reputation: 124768
Use explode instead of split. The result of explode is an array, so use list()
:
list(,$productid) = explode('_', $PagePath, 2);
Note the third parameter, 2 instead of 1. Using 1 will not split anything. Or, just use preg_replace
:
$productid = preg_replace('/^.*?_/', '', $PagePath);
Upvotes: 3