标签:php strpos
由于strpos在找不到内容时返回FALSE,因此,语法:
if(strpos($str,$find)==0){ //...实际是想在找到且位置为0时进入,结果如果找不到也会进入。 }
在找不到时总会进入条件为真的逻辑,因为PHP里FALSE==0为真。
应修改为:
if(strpos($str,$find)===0){ }
类似的不少函数返回值,使用===更安全和准确。
PHP的strpos函数辨析
原文地址:http://livestreaming.blog.51cto.com/3135568/1874545