Wessah Wessah - 7 months ago 11
HTML Question

'Expecting statement' after echo

So PHPStorm gives me a 'expecting statement' error after the following line:

echo $values;


Here's the part in the code:

<?php
if(!empty($_POST)){
$values = implode(', ', array_intersect_key($_POST, $boxes));
$txt = $_POST['Zoeken'];
echo $values;

?>
<br>
<?php
echo $txt;
}
?>


and this is the complete code (form):

<div id="filterList">
<?php $boxes = [
'first_name' => ['label' => 'Voornaam', 'value' => 'a_Voornaam'],
'last_name' => ['label' => 'Achternaam', 'value' => 'a_Achternaam'],
'address' => ['label' => 'Adres', 'value' => 'a_Adres'],
'city' => ['label' => 'Plaats', 'value' => 'a_Woonplaats'],
'zipcode' => ['label' => 'Postcode', 'value' => 'a_Postcode'],
]; ?>
<form name="filter" style="float:left;" method="post">
<table>
<?php foreach ($boxes as $name => $box) { ?>
<tr>
<td>
<label><?php echo $box['label']; ?>:</label>
</td>
<td>
<input type="checkbox" name="<?php echo $name; ?>" id="inh" value="<?php echo $box['value']; ?>"/>
</td>
</tr>
<?php } ?>
<tr>
<td>
<label>Zoeken</label>
</td>
<td>
<input type="text" name="Zoeken" />
</td>
</tr>
<tr>
<td>
<label style="margin-top:5px;"></label>
</td>
<td>
<input id="submitfilter" type="submit" style="margin-top:5px;" class="btn"/>
</td>
</tr>
</table>
<?php
if(!empty($_POST)){
$values = implode(', ', array_intersect_key($_POST, $boxes));
$txt = $_POST['Zoeken'];
echo $values;

?>
<br>
<?php
echo $txt;
}
?>
</form>
</div>


What could be the reason for the error?

Answer

When I copy/paste the code there appears to be an invisible character in the supposedly empty line.

So just remove the blank line indicated by <-- odd character here

        <?php
        if(!empty($_POST)){
            $values = implode(', ', array_intersect_key($_POST, $boxes));
            $txt = $_POST['Zoeken'];
            echo $values;
             <-- odd invisible character here             
            ?>
            <br>
            <?php
            echo $txt;
        }
        ?>