PHP 8.3.4 Released!

strpbrk

(PHP 5, PHP 7, PHP 8)

strpbrkProcura na string por um dos caracteres de um conjunto

Descrição

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

strpbrk() busca na string por qualquer caractere contido em characters.

Parâmetros

string

A string onde characters é procurado.

characters

Este parâmetro é sensível a maiúsculas/minúsculas.

Valor Retornado

Retorna uma string iniciando do caractere encontrado, ou false se nada for encontrado.

Exemplos

Exemplo #1 Exemplo de strpbrk()

<?php

$text
= 'This is a Simple text.';

// isto mostrará "is is a Simple text." porque 'i' aparece primeiro
echo strpbrk($text, 'mi');

// isto mostrará "Simple text." porque a função é sensível a maiúsculas/minúsculas
echo strpbrk($text, 'S');
?>

Veja Também

  • strpos() - Find the position of the first occurrence of a substring in a string
  • strstr() - Find the first occurrence of a string
  • preg_match() - Perform a regular expression match

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