Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Aea

macrumors 6502a
May 23, 2007
838
208
Denver, Colorado
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.
 

Fleetwood Mac

macrumors 65816
Original poster
Apr 27, 2006
1,265
0
Canada
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?
 

Aea

macrumors 6502a
May 23, 2007
838
208
Denver, Colorado
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?

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 :)
 

Fleetwood Mac

macrumors 65816
Original poster
Apr 27, 2006
1,265
0
Canada
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.
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
9
USA
Ugh. That does not sound like fun (I'm a design type after all...)

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 ;)
 

Fleetwood Mac

macrumors 65816
Original poster
Apr 27, 2006
1,265
0
Canada
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 ;)
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.
 

Matteh117

macrumors regular
May 24, 2007
202
0
Surrey, UK
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');
?>
 

Matteh117

macrumors regular
May 24, 2007
202
0
Surrey, UK
And for your information..

The documentation below also applies to require().
The two constructs are identical in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error. In other words, use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.