Placing PHP output in an HTML file.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cheesecaker
    New Member
    • Feb 2007
    • 66

    Placing PHP output in an HTML file.

    This is probably some basic thing that I'm completely overlooking, but I have a PHP file that outputs some text. I'm going to use a simple file as an example:

    [PHP]
    <?php

    $file = $_GET['file'];

    highlight_file( $file);

    ?>
    [/PHP]

    I'd like the highlighted code to show on an HTML page. Maybe a tag in which I could define the SRC to be "highlight.php? file=code.txt". I've tried iframes, but I'd like to avoid those.

    Any ideas?
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Try using include. You can then output highlight.php directly into your page, rather than have the browser make two requests.

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      What is the return value of highlight_file( )? My suspicion would be that it is formatted HTML containing the source code for the file you specified. If this were the case, you would just print or echo it.

      Comment

      • cheesecaker
        New Member
        • Feb 2007
        • 66

        #4
        Ah, nevermind, I solved it. The reason I was having problems was I couldn't figure out how to pass $_GET variables with include:

        [PHP]<?php include('C:/Apache2.2/htdocs/textgen/highlight.php?f ile=textgen.php ');?>[/PHP]

        This does not work because PHP will search for a file named "highlight.php? file=textgen.ph p" on the local filesystem, which doesn't exist.

        However, after reading php.net documentation, I learned that the only way to pass a script variables with $_GET is to use an HTTP address in the include statement. So:

        [PHP]<?php include('www.ex ample.com/textgen/highlight.php?f ile=textgen.php ');?>[/PHP]

        This does work. Thank you for the help, everyone.

        Comment

        • Motoma
          Recognized Expert Specialist
          • Jan 2007
          • 3236

          #5
          Glad you have found your solution. Thank you for posting it here, and come back anytime you have a question.

          Comment

          Working...