lundi 9 juillet 2018

PHP - If in string without leaving the string on str_replace()

$str = '<div class="col-md-4">
    <div class="form-group">
        <label class="text-danger">Present Room Type</label>
        <select class="form-control" name="form-present-room-type" required>
            <option value=""></option>
            <option value="PREMIUM" '.( ("@form-present-room-type@" == "PREMIUM") ? "selected" : "").'>PREMIUM</option>
            <option value="SINGLE" '.( ("@form-present-room-type@" == "SINGLE") ? "selected" : "").'>SINGLE</option>
            <option value="DOUBLE" '.( ("@form-present-room-type@" == "DOUBLE") ? "selected" : "").'>DOUBLE</option>
            <option value="TRIPLE" '.( ("@form-present-room-type@" == "TRIPLE") ? "selected" : "").'>TRIPLE</option>                                    
        </select>
    </div>
</div>';

I questioned it the last time, and I figured out that when I make the if outside the option tag like the above code, the @form-present-room-type@ value was not changed that means @form-present-room-type is not equal with PREMIUM or any of the option values. But when I put it inside the option tag. Like this <option value="PREMIUM" (@form-present-room-type@ == PREMIUM ? selected : "")>PREMIUM</option> he will get the @form-present-room-type@ value, BUT it just returns string like this <option value="PREMIUM" (premium="=" premium="" ?="" selected="" :="" "")="">PREMIUM</option>. Cause I want it to be replaced with certain string like: str_replace('@form-present-room-type@','PREMIUM',$str);

Aucun commentaire:

Enregistrer un commentaire