strpbrk

(PHP 5, PHP 7, PHP 8)

strpbrk在字符串中查找一組字符的任何一個字符

說明

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

strpbrk() 函數(shù)在 haystack 字符串中查找 char_list 中的字符。

參數(shù)

haystack

在此字符串中查找 char_list

char_list

該參數(shù)區(qū)分大小寫。

返回值

返回一個以找到的字符開始的子字符串。如果沒有找到,則返回 false。

范例

示例 #1 strpbrk() 范例

<?php

$text 
'This is a Simple text.';

// 輸出 "is is a Simple text.",因?yàn)?nbsp;'i' 先被匹配
echo strpbrk($text'mi');

// 輸出 "Simple text.",因?yàn)樽址麉^(qū)分大小寫
echo strpbrk($text'S');
?>

參見

  • strpos() - 查找字符串首次出現(xiàn)的位置
  • strstr() - 查找字符串的首次出現(xiàn)
  • preg_match() - 執(zhí)行匹配正則表達(dá)式