PHP 字符串 strpbrk() 函數
strpbrk() 函數是 PHP 的預定義字符串函數。愛掏網 - it200.com它用于在字符串中搜索指定字符中的任意一個字符,或者在字符串中搜索一組字符中的任意一個字符。愛掏網 - it200.com
注意:該函數 strpbrk() 是區分大小寫的。愛掏網 - it200.com
strpbrk(string,charlist);
參數 | 描述 | 必需/可選 |
---|---|---|
string | 指定要搜索的字符串 | 必需 |
charlist | 指定要查找的字符 | 必需 |
它返回自第一個指定字符的第一次出現的位置的字符串的其余部分。愛掏網 - it200.com
示例1
<?php
text = 'Hello javatpoint';
echo "Your string:".text;
echo "<br>";
echo "By using 'strpbrk()' function:".strpbrk($text, 'oe');
?>
輸出:
Your string:Hello javatpoint
By using 'strpbrk()' function:ello javatpoint
示例2
<?php
text = 'This is a Simple text.';
echo "Your string:".text;
echo "<br>";
// this echoes "Simple text." because chars are case sensitive
echo "By using 'strpbrk()' function:".strpbrk($text, 'S');
?>
輸出:
Your string:This is a Simple text.
By using 'strpbrk()' function:Simple text.
示例3
<?php
text = 'This is a Simple text.';
echo "Your string:".text;
echo "<br>";
// this echoes "is is a Simple text." because 'i' is matched first
echo "By using 'strpbrk()' function: ".strpbrk($text, 'mi');
echo "<br>";
?>
輸出:
Your string:This is a Simple text.
By using 'strpbrk()' function: is is a Simple text.
參見
- strcasecmp() :用于比較兩個字符串。愛掏網 - it200.com
- strchr() :用于在另一個字符串中查找第一次出現的字符串。愛掏網 - it200.com
- stscroll():基于地區的字符串比較。愛掏網 - it200.com
- strcmp() :二進制安全的字符串比較。愛掏網 - it200.com
參考:
http://php.net/manual/en/function.strpbrk.php
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。