includes, files

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
rampant
Forum Newbie
Posts: 9
Joined: Thu Oct 08, 2009 2:28 pm

includes, files

Post by rampant »

Ok, this is probably my first post of many as I figure out how to get a page template working using php.

Right now, I am trying to include files, and save their *parsed* output as a variable. I am doing this with ob_start, ob_get_contents, and ob_end_clean. Is there a faster way to get a parsed php file's output into a variable (as a string)?


Secondly, I am including a file, which has a function in it. But then later when I try to call that function in the page, I get a fatal error saying the function doesn't exit. Any ideas?
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: includes, files

Post by flying_circus »

includes/requires really dont allow you to grab that page as a variable. It's just a remote piece of code that isnt run, until it is called.

you could include a file that contains a pre-populated variable, or maybe a function that can be called that will return the output you are looking for.

example:

Code: Select all

<?php
  include_once('includes/php_header.php');
 
  $output = some_function_contained_within_php_header.php();
?>

Secondly, If you are receiving an error, then you either included the remote file AFTER you made a call to it, the include is failing, or there is an error in your code.
rampant
Forum Newbie
Posts: 9
Joined: Thu Oct 08, 2009 2:28 pm

Re: includes, files

Post by rampant »

Ok, cool. I just have the include spitting out a pre-declared variable and then commented in that fact (for my own future reference).
Post Reply