请教一个函数
程序员文章站
2022-05-25 13:41:05
...
请问一个函数
我PHP是菜鸟,判断一变量$a中是否包含另外一个变量中$b的字符,用什么方法可以实现,谢谢
------解决方案--------------------
strpos
$mystring = 'abc ';
$findme = 'a ';
$pos = strpos($mystring, $findme);
// Note our use of ===. Simply == would not work as expected
// because the position of 'a ' was the 0th (first) character.
if ($pos === false) {
echo "The string '$findme ' was not found in the string '$mystring ' ";
} else {
echo "The string '$findme ' was found in the string '$mystring ' ";
echo " and exists at position $pos ";
}
// We can search for the character, ignoring anything before the offset
$newstring = 'abcdef abcdef ';
$pos = strpos($newstring, 'a ', 1); // $pos = 7, not 0
?>
我PHP是菜鸟,判断一变量$a中是否包含另外一个变量中$b的字符,用什么方法可以实现,谢谢
------解决方案--------------------
strpos
$mystring = 'abc ';
$findme = 'a ';
$pos = strpos($mystring, $findme);
// Note our use of ===. Simply == would not work as expected
// because the position of 'a ' was the 0th (first) character.
if ($pos === false) {
echo "The string '$findme ' was not found in the string '$mystring ' ";
} else {
echo "The string '$findme ' was found in the string '$mystring ' ";
echo " and exists at position $pos ";
}
// We can search for the character, ignoring anything before the offset
$newstring = 'abcdef abcdef ';
$pos = strpos($newstring, 'a ', 1); // $pos = 7, not 0
?>
相关文章
相关视频
上一篇: asp.net mvc 5改进了基于过滤器的身份验证
下一篇: php 线程安全编译解决方法