Template: file_get_contents Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Template: file_get_contents Problem

Post by psurrena »

I'm working on a template system and have a question about file_get_contents. In my template file, there is php for sessions, includes and so on. It seems that file_get_contents ignores all PHP, is there a function that does the same thing but doesn't kill the php?

Thanks.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Template: file_get_contents Problem

Post by JAB Creations »

I've never tried this but I'm curious because if there is a solution it would have to do with program execution order...essentially A gets B but B must execute first...PHP in all my experience has (thus far) always done this. On php.net are there any functions in "see also" towards the bottom of the explanation just before the comments? I'm interested in this so I'm subscribed to the thread (but gotta go eat lunch now).
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Template: file_get_contents Problem

Post by Christopher »

Use include() wrapped with the output buffering functions to capture the output.
(#10850)
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Re: Template: file_get_contents Problem

Post by psurrena »

Here's how I have it set up (it's a three file system)...

url: http://www.site.com/index.php?page=home

index.php grabs the value of page and includes the equivalent file, in this case home.php. home.php just includes content (paragraph, image, php). index.php grabs the template and replaces the specified tags with the matching tags in home.php.

Here's another odd thing. In home.php, if I use this code:

Code: Select all

   $test=include('test.php');
    
    $tags['body'].="This is the include: ".$test;
It outputs "This is the include: 1"

When the code in the include is really:

Code: Select all

$text= "<h1>this is an inlcude test</h1>";

I'm not sure I understand about using output buffering (ob_start?). Can you explain?
Post Reply