regex - PHP string how to extract part after pattem to a separate variable -
i have string collects 2 pieces of information. before slash search variable, , after page number.
assume following:
$search = "classic rock/8"
should $searchvalue[0]='classic $searchvalue[1]='rock' $searchvalue[x]= etc... , $page=8
i tried few approaches, last 1 3 passes first removing after slash.
$search=substr($search, 0, strpos($search, '/'));
and separate $search values array. , go (a 3rd time!) , page variable deleting before slash.
i know highly inefficient. there way these actions in 1 pass?
thanks in advance!
you can explode string twice , same results!
$res = explode("/", $search); $page = $res[1]; //this page $searchvalues = explode(" ", $res[0]); //these results
Comments
Post a Comment