Forum Moderators: coopster
but I don't know how can I get a "n" value from the var.
From the array I can get it by $a[n] ($a[0],$a[1]...), but from the var I don't know how to do that.
Each value can be identified by ".n.", but how can I actually choose the n value?
I tried to do that with substr and strpos functions, but that wasn't work.
Maybe the solution is with regex?
Thanks.
$b='.'.$SumNum.'.';
if(strpos($a,$b)!==FALSE) {
/* Do Stuff */
}
Would tell you if SumNum is in the string.
In looking closer, are you trying to find the Nth value?
Then you could just count the dots:
$a = ".10.2.315.407.51.6.179.824.";
$NthNum=4;
preg_match('#^(\.[^.]+){'.($NthNum-1).'}\.([^.]+)#',$a,$NumMatches);
$FoundMatch=array_pop($NumMatches);
echo $FoundMatch;
Should get you close...
Made some minor edits to the regex.
ADDED:
You could probably use a non-capturing pattern for the 1st grouping to be more efficient too...
preg_match('#^(?:\.[^.]+){'.($NthNum-1).'}\.([^.]+)#',$a,$NumMatches);
$FoundMatch=$NumMatches[1];
echo $FoundMatch;