我必须检查字符串中是否存在星号,但它始终显示没有星号.
为什么不起作用strpos()?我也试过stripos(),mb_strpos()和mb_stripos()没有运气.
<?php
$str = "****123";
if(strpos($str, '*') == false){
echo 'There is no asterisk in the string';
} else {
echo 'There is asterisk in the string';
}
Run Code Online (Sandbox Code Playgroud)
字符串中没有星号.
strpos()返回一个整数(0或更多)或FALSE如果没有找到.在PHP中,只有在使用严格相等()时才与它进行比较0和FALSE不同===:
$str = "****123";
if(strpos($str, '*') === false){
echo 'There is no asterisk in the string';
} else {
echo 'There is asterisk in the string';
}
Run Code Online (Sandbox Code Playgroud)
输出:
字符串中有星号