downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

strpos> <strncmp
[edit] Last updated: Fri, 17 May 2013

view this page in

strpbrk

(PHP 5)

strpbrkRecherche un ensemble de caractères dans une chaîne de caractères

Description

string strpbrk ( string $haystack , string $char_list )

strpbrk() recherche l'ensemble de caractères char_list dans la chaîne haystack.

Liste de paramètres

haystack

La chaîne dans laquelle on cherche char_list.

char_list

Ce paramètre est sensible à la casse.

Valeurs de retour

Retourne une chaîne, commençant au premier caractère trouvé, ou FALSE s'il n'a pas été trouvé.

Exemples

Exemple #1 Exemple avec strpbrk()

<?php

$text 
'This is a Simple text.';

// Ceci affichera "is is a Simple text." car 'i' correspond au premier
echo strpbrk($text'mi');

// Ceci affichera "Simple text." car les caractères sont sensibles à la casse
echo strpbrk($text'S');
?>

Voir aussi

  • strpos() - Cherche la position de la première occurrence dans une chaîne
  • strstr() - Trouve la première occurrence dans une chaîne
  • preg_match() - Expression rationnelle standard



add a note add a note User Contributed Notes strpbrk - [2 notes]
up
0
Evan
5 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:

<?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;
}

?>
up
-1
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;
}
?>

 
show source | credits | sitemap | contact | advertising | mirror sites