Reputation: 1345
This is going to sound really simple but I can't understand why its not working.
I am checking that a string matches something to enable some texts to be sent.
The string that is returned is: Delivered to UPS Access Point™ location and awaiting customer pickup.
And this is the statement I am using to check for it
if(strpos(strtolower($step->status), "delivered to ups access point")) {
}
Currently that if statement is returning false when I would expect it to be true
Any ideas
Upvotes: 0
Views: 139
Reputation: 421
This should work
$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";
}
Upvotes: 1
Reputation: 153
You are treating the strpos as if it's a boolean, which is it not. It returns the position of the string which would be 0, and translates to false.
So compare against not false (not found) or >= 0 (found), type is important.
Example:
$data = "Delivered to UPS Access Point™ location and awaiting customer pickup.";
if(strpos(strtolower($data), "delivered to ups access point") !== false) {
echo 'Found!';
}
Upvotes: 5
Reputation: 40
strpos is return index of your second argument. In your case "delivered to ups access point" is starting point mean 0th position. 0 mean false.
Upvotes: 1