检查字符串中是否存在星号

Ars*_*per 2 php

我必须检查字符串中是否存在星号,但它始终显示没有星号.

为什么不起作用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)

期望的输出:

字符串中没有星号.

Sys*_*all 6

strpos()返回一个整数(0或更多)或FALSE如果没有找到.在PHP中,只有在使用严格相等()时才与它进行比较0FALSE不同===:

$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)

输出:

字符串中有星号