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

前端 未结 13 750
无人共我
无人共我 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:01

    For small bits I just keep it all in PHP strings, like when looping through an array to generate a list. But for larger piles of markup I keep that out of the PHP and just drop into PHP when necessary.

    This is largely because I prefer to optimize for maintainability. Not just because it's faster to see what's going on when the html has appropriate syntax highlighting applied, but because it also makes mistakes resulting from a flawed reading of the code less likely to occur.

    There really isn't a best way. I just try to stay consistent with what's described above, and keep my eyes open for situations where maybe the other way would be a better way of handling it.

提交回复
热议问题