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 — Ищет в строке любой символ из набора
Функция strpbrk() ищет в строке string
символы из набора characters
.
string
Строка, в которой производится поиск characters
.
characters
Этот параметр чувствителен к регистру.
Функция возвращает строку, начиная с найденного символа, или false
,
если не нашла символ.
Пример #1 Пример использования функции strpbrk()
<?php
$text = 'This is a Simple text.';
// Этот код выдаст «is is a Simple text.», поскольку символ «i» встретится раньше
echo strpbrk($text, 'mi');
// Этот код выдаст «Simple text.», поскольку символы чувствительны к регистру
echo strpbrk($text, 'S');
?>
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 :<?phpfunction 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;}?>