Php Html Output

Discussion in 'PHP' started by Omzy, Oct 28, 2008.

  1. #1
    I use echo statements to output my HTML code in PHP, however I came across this piece of code:

    
    <?php if ($_POST['Submit'] == "Submit" && !$allvalid) { ?>
    	<div id="downloadbar" class="bad">
    	Please check the fields highlighted in red in order to proceed.
    	</div>
    	<?php } ?>
    
    Code (markup):
    Notice the brackets in the PHP tags - I have never seen this before - is this a valid method of outputting HTML?
     
    Omzy, Oct 28, 2008 IP
  2. unski84

    unski84 Peon

    Messages:
    133
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes, at least I am using this method all the time :)
     
    unski84, Oct 28, 2008 IP
  3. osmasters

    osmasters Well-Known Member

    Messages:
    453
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    100
    #3
    Yes, this is correct method and this is good to have for program where you want to write too many html codes in if or else condition.
     
    osmasters, Oct 28, 2008 IP
  4. Omzy

    Omzy Peon

    Messages:
    249
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    So no need to do echo ' or echo " and have 2 worry about the quotation signs or escaping characters
     
    Omzy, Oct 28, 2008 IP
  5. markowe

    markowe Well-Known Member

    Messages:
    1,136
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    165
    #5
    Yes, I just realised this recently :)

    Bear in mind that the HTML that's outside the php tags will be subject to the conditional statements INSIDE - make sense?

    I can't help feeling this is messy from a "good practice" point of view - probably the purists don't like this kind of chopping and changing from PHP to HTML output and back.
     
    markowe, Oct 28, 2008 IP