strpbrk

(PHP 5, PHP 7, PHP 8)

strpbrkИщет в строке любой символ из заданного набора

Описание

strpbrk(string $string, string $characters): string|false

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

Смотрите также

  • strpos() - Возвращает позицию первого вхождения подстроки
  • strstr() - Находит первое вхождение подстроки
  • preg_match() - Выполняет проверку на соответствие регулярному выражению

add a note add a note

User Contributed Notes 2 notes

up
11
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
3
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