Context : When I use a PHP echo <?= &var ?> in HTML, it causes white space in my HTML element. I have already tried to modify the file with another IDE to be sure that it is not an issue of indents but I have the same result. Same result on Chrome or Firefox...

Problem : The filter of the plugin tablesorter also filters the white spaces and that does not return me the expected result. It works if I manually remove spaces

Question : Is this a PHP syntax error or something else?


My PHP code :

<td class="hidden-sm hidden-xs date">
    <?php if ($approval['STACODEM'] == '200'):?>
    <span data-toggle="popover" data-placement="top" data-trigger="hover focus" data-container="body" data-content="<?= $imgDuesDaysPopover ?>">
        <img src="<?= $imgDueDays ?>" alt="" name="imgDueDays"/>
    </span>
    <?php endif ?>
    <?= $dueDate ?>
</td>

In the Chrome viewer :

enter image description here

The line with a date :

enter image description here

If I filter, no results found :

enter image description here

2 Answers

3
Ozan Kurt On Best Solutions

It's because of your html layout. You can inline your code to solve this.

<td class="hidden-sm hidden-xs date">Everything in here</td>

Or you can customize how the tablesorter orders your rows.

Easiest inlining would be by assigning the result of your if clause to a variable.

<?php 
$img = '';
if ($approval['STACODEM'] == '200') {
    $img = <<<IMG 
    <span data-toggle="popover" data-placement="top" data-trigger="hover focus" data-container="body" data-content="{$imgDuesDaysPopover}">
        <img src="{$imgDueDays}" alt="" name="imgDueDays"/>
    </span>
IMG;
}
?>
<td class="hidden-sm hidden-xs date"><?= $img.$dueDate ?></td>

PS: But be careful, your $img variable will also have spaces if you don't inline it. (Don't know if your tablesorter completely ignores the html.)

1
Harvey On

Thanks to Ozan Kurt, I have stored everything in a variable so the code remains readable.

<?php
    $html = '';
    if ($approval['STACODEM'] == '200') {
        $html .= '<span data-toggle="popover" data-placement="top" data-trigger="hover focus" data-container="body" data-content="' . $imgDuesDaysPopover . '">';
        $html .= '<img src="' . $imgDueDays . '" alt="" name="imgDueDays"/>';
        $html .= '</span>';
    }
    $html .= $dueDate;
?>
<td class="hidden-sm hidden-xs date"><?=$html?></td>