How to make PHP display its code

Discussion in 'PHP' started by JGK, Jul 31, 2007.

  1. #1
    Hi all,

    I'm looking for how to make PHP display its code, including the <? ?>, instead of processing it. This is for the purpose of making a PHP tutorial complete with the code printed on the page.

    Thank you! :)
     
    JGK, Jul 31, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    <?php
    highlight_file($_SERVER['PHP_SELF']);
    ?>
    
    PHP:
     
    nico_swd, Jul 31, 2007 IP
  3. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Depending on your server setup, you may also be able to save your source as .phps and it will automatically highlight it for you.
     
    rodney88, Jul 31, 2007 IP
  4. Philarmon

    Philarmon Peon

    Messages:
    270
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Not sure but i guess your problem is just that your code snippets are not displayed in the HTML because you have .php pages that execute the code ?

    In this case, you just need to encode the "<" and ">" braces - replace all "<" within your code with "&lt;" and all ">" with "&gt;"
     
    Philarmon, Aug 2, 2007 IP
  5. nagasharmi

    nagasharmi Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <?
    echo "t ";
    ?>
     
    nagasharmi, Aug 2, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    ^^ Awesome, I'm impressed.
     
    nico_swd, Aug 2, 2007 IP