I am trying to recognize when a record in my database does not match a word.
I have the following code that works fine when $customer equals Dia , but doesn't work if $customer equals diA
elseif (strpos($cliente, 'Dia') !== false or strpos($cliente, 'plaza') !== false) {
echo "background:#c31434;";
}
I've tried doing it the other way around and it doesn't work either.
elseif (strpos($cliente, 'Dia') == true or strpos($cliente, 'plaza') == true) {
echo "background:#c31434;";
}
I have also tried to do it as @Hector Lopez says in this way, and it does not work the same way as in the case above
elseif ($cliente == 'dia' || $cliente == 'plaza') {
echo "background:#c31434;";
}
This is my complete if
<?php if(strpos($cliente, 'Lupa') !== false or strpos($cliente, 'lupa') !== false or strpos($cliente, 'Tifer') !== false){
echo "background:#1474c3;";
}
elseif ($cliente =='dia' || $cliente =='plaza') {
echo "background:#c31434;";
}
else{
echo "background:#778998;";
};
I would solve this in a more flexible way , creating an array in which the keys would be the color value, and each key would have a sub-array with the values to search for. In this way you won't need to do as many
if
and if in the future you have to incorporate more values/colors you just modify the array and the code would continue working by itself.For the comparison, instead of
strpos
, you usestrripos
, which does the same thing, but is case insensitive , that is, insensitive to upper/lower case.Let's see:
Departure:
Now:
'amarillo'
and assign it the background color#FFFF00
... You would just add this to$arrColors
:'#FFFF00'=>array('amarillo')