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?
Simple is beautiful
function strposX($haystack, $needle, $n = 0)
{
$offset = 0;
for ($i = 0; $i < $n; $i++) {
$pos = strpos($haystack, $needle, $offset);
if ($pos !== false) {
$offset = $pos + strlen($needle);
} else {
return false;
}
}
return $offset;
}
$offset = strposX($result, "\n", $n);
if ($offset === false) {
$offset = strlen($result) - 1;
}