If you're not looking to duplicate the rest of the string, but instead just want the offset, in the spirit of the str*pos() functions, use strcspn()(PHP 5, PHP 7, PHP 8)
strpbrk — Busca un conjunto de caracteres en un string
strpbrk() busca el conjunto de caracteres
characters en el string string.
string
El string en el que se busca characters.
charactersEste argumento distingue entre mayúsculas y minúsculas.
Devuelve un string, comenzando en el primer carácter encontrado,
o false si no se ha encontrado ninguno.
Ejemplo #1 Ejemplo con strpbrk()
<?php
$text = 'This is a Simple text.';
// Esto mostrará "is is a Simple text." porque 'i' coincide con el primero
echo strpbrk($text, 'mi'), PHP_EOL;
// Esto mostrará "Simple text." porque los caracteres distinguen mayúsculas y minúsculas
echo strpbrk($text, 'S'), PHP_EOL;
?>
If you're not looking to duplicate the rest of the string, but instead just want the offset, in the spirit of the str*pos() functions, use strcspn()A little modification to Evan's code to use an array for the second parameter :
<?php
function strpbrkpos($s, $accept) {
$r = FALSE;
$t = 0;
$i = 0;
$accept_l = count($accept);
for ( ; $i < $accept_l ; $i++ )
if ( ($t = strpos($s, $accept[$i])) !== FALSE )
if ( ($r === FALSE) || ($t < $r) )
$r = $t;
return $r;
}
?>