I understand that this function will get the first occurrence of the string.
But what I want is the 2nd occurrence.
How to go about doing that?
function substr_Index( $str, $nth ){
$str2 = '';
$posTotal = 0;
for($i=0; $i < $nth; $i++){
if($str2 != ''){
$str = $str2;
}
$pos = strpos($str, ':');
$str2 = substr($str, $pos+1);
$posTotal += $pos+1;
}
return $posTotal-1;
}
echo substr($mystring, substr_Index( $mystring , 2) );
Function returns position of nth delimiter.
Second parameter of substr_Index
must be bigger than 0;
To find second occourance use substr_Index( $mystring , 2)