本文介绍了如何使用strpos确定输入字符串中是否存在字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$filename = 'my_upgrade(1).zip';
$match = 'my_upgrade';
if(!strpos($filename, $match))
{
die();
}
else
{
//proceed
}
在上面的代码中,当文件名不包含文本字符串"my_upgrade"时,我试图退出脚本.但是,在给出的示例中,它不会死,因为" my_upgrade(1).zip "包含字符串" my_upgrade ".
In the code above, I'm trying to die out of the script when the filename does not contain the text string "my_upgrade". However, in the example given, it should not die since "my_upgrade(1).zip" contains the string "my_upgrade".
我想念什么?
推荐答案strpos如果找不到该字符串,则返回false,如果在开头找到该字符串,则返回0.使用身份运算符来区分两者:
strpos returns false if the string is not found, and 0 if it is found at the beginning. Use the identity operator to distinguish the two:
if (strpos($filename, $match) === false) {顺便说一句,官方文件.
更多推荐
如何使用strpos确定输入字符串中是否存在字符串?
发布评论