PHP 8.3.4 Released!

strpbrk

(PHP 5, PHP 7, PHP 8)

strpbrk Ricerca in una stringa uno qualsiasi dei caratteri di un dato set

Descrizione

strpbrk(string $haystack, string $char_list): string

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_list distingue 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');
?>

add a note

User Contributed Notes 2 notes

up
15
devnuhl
9 years ago
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()
up
6
guillaume dot barranco at free dot fr
6 years ago
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;
}

?>
To Top