How can I echo HTML in PHP?

后端 未结 13 2278
耶瑟儿~
耶瑟儿~ 2020-11-22 06:40

I want to conditionally output HTML to generate a page, so what\'s the easiest way to echo multiline snippets of HTML in PHP 4+? Would I need to use a template framework lik

13条回答
  •  有刺的猬
    2020-11-22 07:23

    Basically you can put HTML anywhere outside of PHP tags. It's also very beneficial to do all your necessary data processing before displaying any data, in order to separate logic and presentation.

    The data display itself could be at the bottom of the same PHP file or you could include a separate PHP file consisting of mostly HTML.

    I prefer this compact style:

    
    
    
    
        <?=$title?>
    
    
        
            

    Note: you may need to use instead of depending on your PHP setup.

提交回复
热议问题