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:
<?php
function strpbrkpos($s, $accept) {
$r = FALSE;
$t = 0;
$i = 0;
$accept_l = strlen($accept);
for ( ; $i < $accept_l ; $i++ )
if ( ($t = strpos($s, $accept{$i})) !== FALSE )
if ( ($r === FALSE) || ($t < $r) )
$r = $t;
return $v;
}
?>
strpbrk
(PHP 5)
strpbrk — Ricerca in una stringa uno qualsiasi dei caratteri di un dato set
Descrizione
string strpbrk
( string
$haystack
, string $char_list
)
strpbrk() cerca nella stringa haystack
i caratteri indicati in char_list, e restituisce una
stringa a partire dal carattere trovato (oppure FALSE se non ve ne sono).
Nota:
char_listdistingue tra maiuscole e minuscole.
Example #1 Esempio di uso di strpbrk()
<?php
$text = 'This is a Simple text.';
// visualizza "is is a Simple text." because 'i' is matched first
echo strpbrk($text, 'mi');
// visualizza "Simple text." because chars are case sensitive
echo strpbrk($text, 'S');
?>
Evan ¶
5 years ago
root at mantoru dot de ¶
5 years ago
A simpler (and slightly faster) strpbrkpos function:
<?php
function strpbrkpos($haystack, $char_list) {
$result = strcspn($haystack, $char_list);
if ($result != strlen($haystack)) {
return $result;
}
return false;
}
?>
