PHP函数strpbrk()用于在一个字符串中查找一组字符的任何一个出现位置,并返回该位置及其后面的所有字符
▥php
𝄐 0
phpstudy,phpstudy数据库,phpstudy怎么下载,phpstudy的MySQL打不开,phpstudy怎么启动web服务,phpstudy启动MySQL教程
PHP函数strpbrk()用于在一个字符串中查找一组字符的任何一个出现位置,并返回该位置及其后面的所有字符。它接受两个参数:第一个参数是要搜索的字符串,第二个参数是要查找的字符集合。
语法:
string strpbrk ( string $haystack , string $char_list )
示例:
// 在字符串中查找是否存在特定字符
$mystring = 'hello world';
$findme = 'w';
$pos = strpbrk($mystring, $findme);
if ($pos !== false) {
echo "The string $findme was found in the string $mystring starting from position $pos";
} else {
echo "The string $findme was not found in the string $mystring";
}
/*
输出:
The string w was found in the string hello world starting from position 6
*/
// 查找一组可能出现的字符
$mystring = 'The quick brown fox';
$findme = 'aeiou';
$pos = strpbrk($mystring, $findme);
if ($pos !== false) {
echo "One of the vowels was found in the string $mystring starting from position $pos";
} else {
echo "None of the vowels were found in the string $mystring";
}
/*
输出:
One of the vowels was found in the string The quick brown fox starting from position 2
*/
在上面的例子中,第一个例子查找了字符串中特定字符的位置,而另一个例子查找了一组可能出现字符的位置。
PHP函数strpbrk()用于在一个字符串中查找一组字符的任何一个出现位置,并返回该位置及其后面的所有字符。它接受两个参数:第一个参数是要搜索的字符串,第二个参数是要查找的字符集合。
语法:
string strpbrk ( string $haystack , string $char_list )
示例:
// 在字符串中查找是否存在特定字符
$mystring = 'hello world';
$findme = 'w';
$pos = strpbrk($mystring, $findme);
if ($pos !== false) {
echo "The string $findme was found in the string $mystring starting from position $pos";
} else {
echo "The string $findme was not found in the string $mystring";
}
/*
输出:
The string w was found in the string hello world starting from position 6
*/
// 查找一组可能出现的字符
$mystring = 'The quick brown fox';
$findme = 'aeiou';
$pos = strpbrk($mystring, $findme);
if ($pos !== false) {
echo "One of the vowels was found in the string $mystring starting from position $pos";
} else {
echo "None of the vowels were found in the string $mystring";
}
/*
输出:
One of the vowels was found in the string The quick brown fox starting from position 2
*/
在上面的例子中,第一个例子查找了字符串中特定字符的位置,而另一个例子查找了一组可能出现字符的位置。
本文地址:
/show-270879.html
版权声明:除非特别标注原创,其它均来自互联网,转载时请以链接形式注明文章出处。