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 — Durchsucht einen String nach einem Zeichen aus einer Gruppe von Zeichen
strpbrk() durchsucht den String
string nach dem ersten Vorkommen eines Zeichens
aus characters.
string
Die Zeichenkette, in der characters gesucht
werden soll.
charactersDieser Parameter berücksichtigt Groß- und Kleinschreibung.
Gibt den Rest des Strings, beginnend bei der ersten Fundstelle, zurück;
falls kein Zeichen gefunden wird jedoch false.
Beispiel #1 strpbrk()-Beispiel
<?php
$text = 'Dies ist ein einfacher Text.';
// Gibt "ies ist ein einfacher Text." aus, da 'i' als erstes gefunden wird
echo strpbrk($text, 'ti'), PHP_EOL;
// Gibt "Text." aus, da Groß- und Kleinschreibung berücksichtigt wird
echo strpbrk($text, 'T'), 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;
}
?>