Code to display my code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michelle

    Code to display my code

    Hi all,

    I am taking a class in PHP and thought that it would be nice to display
    the PHP code that generated my pages when the user clicked a link (or
    submit button). I have seen page that will display the underlying HTML
    on the page and it would be a nice touch...I think

    Is there a way to do this?

    TIA,

    Miki
  • Pedro Graca

    #2
    Re: Code to display my code

    Michelle wrote:[color=blue]
    > I am taking a class in PHP and thought that it would be nice to display
    > the PHP code that generated my pages when the user clicked a link (or
    > submit button). I have seen page that will display the underlying HTML
    > on the page and it would be a nice touch...I think
    >
    > Is there a way to do this?[/color]



    Example:

    <?php
    echo '<p>Hello World!</p>';
    highlight_file( $_SERVER['PHP_SELF']);
    ?>

    The HTML output is (reformatted):

    <p>Hello World!</p><code>
    <font color="#000000" >
    <font color="#0000CC" >&lt;?php<br /></font>
    <font color="#006600" >echo </font>
    <font color="#CC0000" >'&lt;p&gt;Hell o World!&lt;/p&gt;'</font>
    <font color="#006600" >];<br/></font>
    <font color="#0000CC" >highlight_file </font>
    <font color="#006600" >(</font>
    <font color="#0000CC" >$_SERVER</font>
    <font color="#006600" >[</font>
    <font color="#CC0000" >'PHP_SELF'</font>
    <font color="#006600" >]</font>
    <font color="#006600" >);<br /></font>
    <font color="#0000CC" >?&gt;<br /></font>
    </font>
    </code>
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    • CountScubula

      #3
      Re: Code to display my code

      "Michelle" <miki@spam_me.n et> wrote in message
      news:J_RUb.2409 02$na.397133@at tbi_s04...[color=blue]
      > Hi all,
      >
      > I am taking a class in PHP and thought that it would be nice to display
      > the PHP code that generated my pages when the user clicked a link (or
      > submit button). I have seen page that will display the underlying HTML
      > on the page and it would be a nice touch...I think
      >
      > Is there a way to do this?
      >
      > TIA,
      >
      > Miki[/color]

      <HTML>
      <BODY>
      <?php
      $whatFile = "source_php_fil e_";
      highlight_file( $whatFile)
      ?>
      </BODY>
      </HTML>

      --
      Mike Bradley
      http://www.gzentools.com -- free online php tools



      Comment

      • steven mestdagh

        #4
        Re: Code to display my code

        Michelle <miki@spam_me.n et> wrote:[color=blue]
        > Hi all,
        >
        > I am taking a class in PHP and thought that it would be nice to display
        > the PHP code that generated my pages when the user clicked a link (or
        > submit button). I have seen page that will display the underlying HTML
        > on the page and it would be a nice touch...I think
        >
        > Is there a way to do this?[/color]

        sounds like you want to use fopen, fread and fclose functions to read your
        script into a variable and then display it.
        your current script's filename is in the variable
        $_SERVER["SCRIPT_FILENAM E"]

        so you'll end up with something like:

        $filename = $_SERVER["SCRIPT_FILENAM E"];
        $filehandle = @fopen($filenam e, "r");
        $contents = fread($filehand le, filesize($filen ame));
        @fclose($handle );

        next, display $contents in any way you like. you can also use file()
        function to read the file into an array, etc.
        note that the @ prevents error messages from displaying and revealing
        your script's location when an error occurs, which is more secure.

        steven.

        Comment

        • Geoff Berrow

          #5
          Re: Code to display my code

          I noticed that Message-ID: <J_RUb.240902$n a.397133@attbi_ s04> from
          Michelle contained the following:
          [color=blue]
          >I am taking a class in PHP and thought that it would be nice to display
          >the PHP code that generated my pages when the user clicked a link (or
          >submit button). I have seen page that will display the underlying HTML
          >on the page and it would be a nice touch...I think[/color]

          You could save the file with a .phps extension which makes the code
          visible and nicely coloured.
          --
          Geoff Berrow (put thecat out to email)
          It's only Usenet, no one dies.
          My opinions, not the committee's, mine.
          Simple RFDs http://www.ckdog.co.uk/rfdmaker/

          Comment

          • Tim Tyler

            #6
            Re: Code to display my code

            Michelle <miki@spam_me.n et> wrote or quoted:
            [color=blue]
            > I am taking a class in PHP and thought that it would be nice to display
            > the PHP code that generated my pages when the user clicked a link (or
            > submit button). I have seen page that will display the underlying HTML
            > on the page and it would be a nice touch...I think
            >
            > Is there a way to do this?[/color]

            There is PHP code to display HTML and PHP code (or a mixture of the two) -
            with appropriate syntax highlighting for both languages - at:


            --
            __________
            |im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply.

            Comment

            Working...