Forum Moderators: coopster

Message Too Old, No Replies

Getting include() content

include(index.php);

         

rokec

7:58 pm on Sep 19, 2006 (gmt 0)

10+ Year Member



How can i get content of index.php, if i previously included it with include(index.php);?

whoisgregg

10:23 pm on Sep 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's not possible to retroactively capture the string of a file that has already been included.

However, you can get the contents of a file as easily as you can include that file as a separate action.

file_get_contents [php.net] is handy for reading a file into a variable and more information about the include function [php.net] is a worthwhile read as it includes an alternate method (using output buffering) to include a PHP file into a string.

Psychopsia

11:05 pm on Sep 19, 2006 (gmt 0)

10+ Year Member



You can get the included file contents using ob_get_contents [us2.php.net] and store it in a var.

Try with this code:

ob_start();

include('index.php');

$content = ob_get_contents();
ob_end_clean();

Hope this helps! :)