Showing HTML code in PHP

Discussion in 'PHP' started by Nerve, Oct 14, 2007.

  1. #1
    Hello

    How can I show a HTML code in PHP?

    Such as:

    <?
    echo '
    <form method="post" action=""><br/>
    <!-- Inputs Go Here --><br/>
    </form>';
    ?>

    Without it actually creating the form, so on the page you would see the code:
    <form method="post" action="">
    <!-- Inputs Go Here -->
    </form>

    Any help is appreciated.

    Edit, never mind, found out I had to use character entities.
     
    Nerve, Oct 14, 2007 IP
  2. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #2
    use double quotes and escape the quotes inside like....

     
    olddocks, Oct 14, 2007 IP
  3. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Don't use PHP...
    <?php // Any code
    ?>
    <pre>
    <form method="post" action="">
    <!-- Inputs Go Here -->
    </form>
    </pre>
    <?php // Any more code
    ?>
     
    Danltn, Oct 14, 2007 IP
  4. tandac

    tandac Active Member

    Messages:
    337
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Better still, don't put HTML code in your PHP files. :) Use a template library such as smarty or phplib's instead.
     
    tandac, Oct 14, 2007 IP
  5. Nerve

    Nerve Peon

    Messages:
    467
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    When I use Pre it does not work, it goes right to the actually html.
     
    Nerve, Oct 14, 2007 IP
  6. tandac

    tandac Active Member

    Messages:
    337
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Maybe I'm getting completely off base...
    
    <?php
      $str="<p>Some Example</p>";
      echo htmlentities($str);
    ?>
    
    Code (markup):
     
    tandac, Oct 14, 2007 IP
  7. cristalron

    cristalron Peon

    Messages:
    19
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Like this:;)
    &lt;form method=&quot;post&quot; action=&quot;&quot;&gt;&lt;br/&gt;<br />
    &lt;!-- Inputs Go Here --&gt;&lt;br/&gt;<br />
    &lt;/form&gt;'
     
    cristalron, Oct 15, 2007 IP
  8. jonimontana

    jonimontana Well-Known Member

    Messages:
    262
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #8
    
    You can use ADV echo...
    
    <?php
    echo <<<html
    <form action="ccc.php" method='post>
    ...
    </form>
    html;
    ?>
    
    Code (markup):
     
    jonimontana, Oct 15, 2007 IP
  9. Invent

    Invent Peon

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    
    <?php
    
    echo htmlentities('
    <form method="post" action=""><br/>
    <!-- Inputs Go Here --><br/>
    </form>');
    
    ?>
    
    PHP:
    EDIT: Oops, never realised you found out how to do it.
     
    Invent, Oct 15, 2007 IP