I want capture Rank from this code :
$RankStr = 'var trafficstatsSnippet = "/site/trafficstats;pysa1bpbPOVl6Wm5d4Zv4nKXKdM%3D
/aahoonet.com/?adult=&category=&rank=1234567";'
I use this code :
$NewPOS = strpos($RankStr, "rank="); $SRank = substr($RankStr, $NewPOS + 5, 10); echo $SRank;
because of RANK code variable from (1 - 25,000,000) , i use above code by selecting maximum 10 charachters after starting position of rank= plus 5 further index.
so this function return
1234567";
and after that i want to grab this number from string. trying preg_match_all
or regex
but becasue of nofamiliarity with these functions i cant gain any usable response.
Please Help me for this problem, If there is more solution please provide them!
You can use preg_match as:
if(preg_match('/rank=(\d+)/',$RankStr,$m)) {
$rank = $m[1];
}
来源:https://stackoverflow.com/questions/4175941/a-simple-function-for-return-number-from-string-in-php