Including output of a PHP file...

Discussion in 'Web Design and Development' started by Fleetwood Mac, Aug 17, 2007.

  1. Fleetwood Mac macrumors 65816

    Fleetwood Mac

    Joined:
    Apr 27, 2006
    Location:
    Canada
    #1
    I'm trying to include the HTML output of one PHP file into my new PHP file. Is this possible?
     
  2. Aea macrumors 6502a

    Aea

    Joined:
    May 23, 2007
    Location:
    Denver, Colorado
    #2
    Are you trying to manually paste the output of a PHP script into a new PHP script, or do you want a PHP script to generate a new PHP file from itself including that output?

    In either case you'd have to escape (particularly the "s), I haven't done PHP in a while, but str_replace() should work nicely for automatically escaping.
     
  3. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #3
    Could you elaborate on what you're wanting to do and the context you're doing it in?
     
  4. Fleetwood Mac thread starter macrumors 65816

    Fleetwood Mac

    Joined:
    Apr 27, 2006
    Location:
    Canada
    #4
    Well here's the thing. Script 1 is connected to my forum. As new posts are added, it displays them. I want to include the HTML output of Script 1 on my website (located in a different directory).

    Is that enough info?
     
  5. Aea macrumors 6502a

    Aea

    Joined:
    May 23, 2007
    Location:
    Denver, Colorado
    #5
    You could do something like creating a database to share in between where the output is simply stored as a row.

    Or you could create a .txt file which both scripts have access to and store the output there.

    For this method then both are equally fast, the latter is probably a lot faster to implement. Of course you could do something more complex if you wanted to :)
     
  6. Fleetwood Mac thread starter macrumors 65816

    Fleetwood Mac

    Joined:
    Apr 27, 2006
    Location:
    Canada
    #6
    Ugh. That does not sound like fun (I'm a design type after all...)

    There's no way to grab the output of a PHP file as if were just an HTML file, eh? Here's the code in the script that grabs the posts (the one I want the output of).

    Code:
    <?php
    // Recent Posts Plugin
    // By Rogem
    // Version 1.0
    
    define("IN_MYBB", 1);
    define("KILL_GLOBALS", 1);
    define("NO_ONLINE", 1);
    
    // The Directory to the forum you are using this on. 
    // You do not need a beggining or trailing slash
    $directory_to_forum = ""; 
    
    require dirname(__FILE__)."/".$directory_to_forum."/global.php";
    
    $plugins->run_hooks("Recent_Posts_Plugin_run");
    ?>
    
    Of course, this is just the final of a few files.. and some funky database voodoo.
     
  7. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #7
    It may not be fun, but it's probably the most direct way to handle your question if I'm understanding it correctly. It's not that bad either. Perhaps you should consider the overall effect you're going for and think of a new direction to solving it. Some times things are hard because you're taking the hard approach ;)
     
  8. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
  9. Fleetwood Mac thread starter macrumors 65816

    Fleetwood Mac

    Joined:
    Apr 27, 2006
    Location:
    Canada
    #9
    Great advice. I had over complicated everything. I ended up writing my own script and everything works great now.

    Thank you to everyone for your help.
     
  10. Matteh117 macrumors regular

    Joined:
    May 24, 2007
    Location:
    Surrey, UK
    #10
    From what I understand, you want one PHP page inside another loaded from different locations. You _can_ pass variables between the two.

    If what I'm suggesting is correct, then an include would do fine.

    PHP:
    <?php
    include('path/to/filename.php');
    ?>
     
  11. savar macrumors 68000

    savar

    Joined:
    Jun 6, 2003
    Location:
    District of Columbia
    #11
    It's really simple.

    Code:
    <?php
    require("path_to_my_other_php_file.php");
    ?>
     
  12. Matteh117 macrumors regular

    Joined:
    May 24, 2007
    Location:
    Surrey, UK
    #12
    And for your information..

     

Share This Page