I am trying to solve an issue with a function stripos in PHP. We are doing promo codes and for instance, one promo code is "friends" and another is "friends40" and when someone types that in, it is saying that both of these are true so it will give them a double discount.
We need these to be distinct but not case sensitive. Is there a technique or another function we can use?
if (stripos($promo,'friends') !== false) {
$price = $price/2;
$adddiscount = .50;
}
if (stripos($promo,'FRIENDS40') !== false) {
$price = $price - $price * .4;
$adddiscount = .4;
}
Both will validate as
striposis case-insensitive andfriendscan be found inFRIENDS40. You need to do theFRIENDS40check first then thefriendsAn alternative would be to use strpos() which IS case-sensitive:
To be on the safe side I would recommend using the first method.