This is SUPPOSED to get the location of the Xth occurance of a character in a string, where $xpos is the occurance that you want to get, and $xchar is the character that you want to get.
function strxpos($xtext,$xchar,$xpos){
$pshchar=strpos($xtext,$xchar);
$owut=0;
for($numon=1;$numon <= $xpos;$numon++){
$result=strpos($xtext,$xchar,$owut);
$owut=(strpos($xtext,$xchar,$owut) + 1);
}
return $result;
}
It works to an extent.
Say that there are only 5 occurances in the string, but the number for $xpos is 7. It will still retrieve a number, which I don't want it to do, for some reason its really wierd, i've tried replacing it with
function strxpos($xtext,$xchar,$xpos){ //strxpos('a.b.c.d.e','.',3) returns 5 (first char in string is 0)
$nrchars=substr_count($xtext,$xchar);
$pshchar=strpos($xtext,$xchar);
$owut=0;
for($numon=1;$numon <= $xpos || $numon <= $nrchars;$numon++){
$result=strpos($xtext,$xchar,$owut);
$owut=(strpos($xtext,$xchar,$owut) + 1);
}
return $result;
}
but still it bears no fruit, it just doesn't work at all when I change it to that. Any tips would be greatly appreciated.
Thanks,
Trink