PHP: How to hide/display chunks of HTML

前端 未结 4 1191
误落风尘
误落风尘 2021-02-06 09:18

I\'m hoping someone can help with this very newbie question. I\'ve just come from an ASP.Net environment where it was easy to hide or show chunks of HTML. For example: Different

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-06 09:56

    You don't need to put the HTML into an echo statement. Think of the HTML as implicitly being echoed. So, for conditionally showing a chunk of HTML, you'd be looking for a construct like this:

    
        

    Some content

    So the HTML string literal that exists outside of the PHP tags is just implicitly delivered to the page, but you can wrap logic around it to drive it. In the above, the div and its contents are all within the scope of the if statement, and so that chunk of HTML (even though it's outside of the PHP tags) is only delivered if the condition in the PHP code is true.

提交回复
热议问题