©
Dokumen ini menggunakan Manual laman web PHP Cina Lepaskan
(PHP 5)
strpbrk — 在字符串中查找一组字符的任何一个字符
$haystack
, string $char_list
) strpbrk() 函数在 haystack
字符串中查找 char_list
中的字符。
haystack
在此字符串中查找 char_list
。
char_list
该参数区分大小写。
返回一个以找到的字符开始的子字符串。如果没有找到,则返回 FALSE
。
Example #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' );
?>
[#1] devnuhl [2014-07-11 20:12:44]
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()
[#2] Evan [2007-07-03 20:33:06]
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;
}
?>