Escape HTML to PHP or Use Echo? Which is better?

前端 未结 13 668
无人共我
无人共我 2020-12-01 04:34

In terms of performance , what would be better. Using PHP to echo all the HTML output so I can pepper it with the various bits of working code and variables or escape HTML t

相关标签:
13条回答
  • 2020-12-01 05:10

    I don't know about the performance of this, but within PHP you can also use what I believe is called a "Heredoc", which I think helps with readability within this sort of output.

    Nickf's example:

    <table>
        <tr>
            <td colspan="<?php echo $numCols; ?>">
                <?php echo $a; ?>, <?php echo $b; ?>, and <?php echo $c?>
            </td>
        </tr>
    </table>
    

    becomes:

    <?php
    echo <<<EOT
    <table>
        <tr>
            <td colspan="$numCols">
                $a , $b, and  $c
            </td>
        </tr>
    </table>
    
    EOT;
    
    ?>
    

    I do believe that ultimately readability is a subjective thing, so your mileage may vary!

    Ruth

    0 讨论(0)
提交回复
热议问题