Вы можете использовать что-то вроде следующего:
/* Function copied from the php manual comment you referenced */
function strnripos_generic( $haystack, $needle, $nth, $offset, $insensitive, $reverse )
{
// If needle is not a string, it is converted to an integer and applied as the ordinal value of a character.
if( ! is_string( $needle ) ) {
$needle = chr( (int) $needle );
}
// Are the supplied values valid / reasonable?
$len = strlen( $needle );
if( 1 > $nth || 0 === $len ) {
return false;
}
if( $insensitive ) {
$haystack = strtolower( $haystack );
$needle = strtolower( $needle );
}
if( $reverse ) {
$haystack = strrev( $haystack );
$needle = strrev( $needle );
}
// $offset is incremented in the call to strpos, so make sure that the first
// call starts at the right position by initially decreasing $offset by $len.
$offset -= $len;
do
{
$offset = strpos( $haystack, $needle, $offset + $len );
} while( --$nth && false !== $offset );
return false === $offset || ! $reverse ? $offset : strlen( $haystack ) - $offset;
}
// Our split function
function mysplit ($haystack, $needle, $nth) {
$position = strnripos_generic($haystack, $needle, $nth, 0, false, false);
$retval = array();
if ($position !== false) {
$retval[0] = substr($haystack, 0, $position-1);
$retval[1] = substr($haystack, $position);
return $retval;
}
return false;
}
Тогда вы просто используете функцию mysplit, вы получите массив с двумя подстроками.Первый содержит все символы вплоть до n-го вхождения иглы (не включены), а второй - от n-го вхождения иглы (в комплекте) до конца.