what is the recommended way to embed html codes inside php codes?

后端 未结 5 786
温柔的废话
温柔的废话 2020-12-11 08:55

Lets say I have 2 cases:


v.s



html codes goes here



        
5条回答
  •  悲哀的现实
    2020-12-11 09:22

    Oh, for the sake of all those who edit your code later, please never put any significant amount HTML code inside a string and echo it out. In any language.

    HTML belongs in HTML files, formatted and styled by your IDE or editor, so it can be read. Giant string blocks are the biggest cause of HTML errors I have ever seen.

    Performance shouldn't matter too much, in this case, but I would assume the second would be faster, because it is streamed directly to the output or buffer.

    If you want it to be easier to read, enable short tags, and write it like this:

    ?>blah blah blah

    Plus, with short tags enabled, it's easier to echo out variables:

    Hello, 
    

    If you are using this to generate some sort of reusable library, there are other options.

提交回复
热议问题