mb_strrpos throws a warning if $haystack is empty.
strrpos simply returns FALSE.
This is something to be wary of if overloading the mb functions.
(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
mb_strrpos — Localiza la última ocurrencia de un carácter en una cadena
mb_strrpos() realiza una búsqueda de tipo
strpos(), teniendo en cuenta los caracteres
multioctetos. La posición de needle
se cuenta
a partir del inicio de la cadena haystack
: las
posiciones comienzan en 0.
haystack
La cadena a analizar.
needle
La cadena a buscar en la cadena haystack
.
offset
encoding
The encoding
parameter is the character encoding. If it is omitted or null
, the internal character
encoding value will be used.
Devuelve la posición numérica de
la última ocurrencia del carácter needle
en la
cadena haystack
. Si needle
no
es encontrado, mb_strrpos() devuelve false
.
Versión | Descripción |
---|---|
8.0.0 |
needle now accepts an empty string.
|
8.0.0 |
Pasar encoding como tercer argumento
en lugar de offset ha sido eliminado.
|
8.0.0 |
encoding is nullable now.
|
mb_strrpos throws a warning if $haystack is empty.
strrpos simply returns FALSE.
This is something to be wary of if overloading the mb functions.
"Negative values will stop searching at an arbitrary point prior to the end of the string. " ist misleading.
The needle may not fully part of searchrange, defined by a negative offset.
A negative offsets marks the last byte, where a search could start.
<?php
$test = "Hallo, Herr Gött";
var_dump(strlen($test)); // int(17)
var_dump(mb_strrpos($test,'ött',13)); // int(13)
var_dump(mb_strrpos($test,'ött',-4)); // int(13) 17-4 = 13
var_dump(mb_strrpos($test,'ött',-5)); // bool(false)
?>