Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当项目匹配时,PHP strpos不返回true_Php - Fatal编程技术网

当项目匹配时,PHP strpos不返回true

当项目匹配时,PHP strpos不返回true,php,Php,这听起来很简单,但我不明白为什么它不起作用 我正在检查字符串是否与某些内容匹配,以便能够发送某些文本 返回的字符串是:传递到UPS接入点™ 位置和等待客户取货。 这是我用来检查它的声明 if(strpos(strtolower($step->status), "delivered to ups access point")) { } 目前,if语句返回false,而我期望它为true 任何想法您将strpo视为布尔值,而不是布尔值。它返回字符串的位置,该位置为0,并转换为false 因

这听起来很简单,但我不明白为什么它不起作用

我正在检查字符串是否与某些内容匹配,以便能够发送某些文本

返回的字符串是:
传递到UPS接入点™ 位置和等待客户取货。

这是我用来检查它的声明

if(strpos(strtolower($step->status), "delivered to ups access point")) {

}
目前,if语句返回false,而我期望它为true


任何想法

您将strpo视为布尔值,而不是布尔值。它返回字符串的位置,该位置为0,并转换为false

因此,与not false(未找到)或>=0(已找到)相比,类型很重要

例如:

    $data = "Delivered to UPS Access Point™ location and awaiting customer pickup.";
    if(strpos(strtolower($data), "delivered to ups access point") !== false) {
     echo 'Found!';
    }

您将strpo视为布尔值,而不是布尔值。它返回字符串的位置,该位置为0,并转换为false

因此,与not false(未找到)或>=0(已找到)相比,类型很重要

例如:

    $data = "Delivered to UPS Access Point™ location and awaiting customer pickup.";
    if(strpos(strtolower($data), "delivered to ups access point") !== false) {
     echo 'Found!';
    }
这应该行得通

$step->status = "Delivered to UPS Access Point™ location and awaiting customer pickup.";
if(strpos(strtolower($step->status), "delivered to ups access point") !== false) {
    echo "String matches";
}
else {
    echo "String not matches";
}
这应该行得通

$step->status = "Delivered to UPS Access Point™ location and awaiting customer pickup.";
if(strpos(strtolower($step->status), "delivered to ups access point") !== false) {
    echo "String matches";
}
else {
    echo "String not matches";
}

strpos是第二个参数的返回索引。在您的情况下,“交付至ups接入点”是起点,表示第0个位置。0表示false。

strpos是第二个参数的返回索引。在您的情况下,“交付至ups接入点”是起点,表示第0个位置。0表示错误。

非常感谢,完全忘记了这是如此的回报每个人都有这样的时刻;)
strpos
返回
false
如果找不到,则不会返回
-1
。非常感谢,完全忘记了这样返回每个人都有这样的时刻;)
strpos
返回
false
如果未找到,则不返回
-1