How can I print html code to a page?

Discussion in 'PHP' started by Imozeb, Mar 26, 2010.

  1. #1
    I want to debug one of my scripts which outputs html code to a page for processing, since the code goes through AJAX I cannot see the source.
    I have a variable that I am outputing containing the html script. How could I acctually see the html code itself and not just what the web browser parses the code into? I was thinking something like escaping the html tags but it isn't working.

    Thanks.

    ~imozeb :)
     
    Imozeb, Mar 26, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Use highlight_string() on the variable which contains the html.

    <?php
    /* PS: highlight_string() is for printing php code - however in this case its probably the best as its more convenient then escaping tags etc. - to display the html correctly. */
    $html = '<body>stuff...</body>';
    highlight_string($html);
    
    ?>
    PHP:
     
    danx10, Mar 26, 2010 IP
  3. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks danx10.
     
    Imozeb, Mar 26, 2010 IP