Search code examples
phpstrpos

strpos() == '' fails to find match at start of string


ScreenShot

It's working fine for all comma-separated values, but not working for Restaurant. Please suggest what should I have to do this.

$service = "Restaurant,24x7_room_service,Parking,currency_exchange,deposite_boxes,Laundry,pool,gym,AC,TV,Fridge,Intercom,Intercom,Extra Bed (if needed Chargeable)";
                            
//$dservices = str_ireplace(',', ' ', $d['services']);
$dservices = "Restaurant,24x7_room_service,Parking,currency_exchange,deposite_boxes,Laundry,pool,gym,AC,TV";
$loop = explode(",", $service);
                            
foreach ($loop as $action)
{
    ?>
    <li style="width:50%; float:left; padding: m10px;">
        <?php  
        if (strpos($dservices, $action) == '') {
            echo '<i style="color:red;" class="fa fa-times-circle"></i>';
        } else {
            ?><i style="color:#004386;" class="fa fa-check-circle"></i><?php
        }
        ?>
        <?= $action ?>
    </li>
    <?php
}
?>

Solution

  • Replace your if condition with the following :

    if(strpos($dservices, $action) === false)