views:

91

answers:

1

I'm currently using PHP's mail() function to email the HTML Body of another PHP file using concatenation.

This is currently working fine, however, I would prefer the script to simply get the parsed HTML Body rather than using the concatenation method.

I've read a few incomplete forum posts regarding using fopen() and fread() but had no luck myself. Any output I have got to work has not parsed the PHP within the file.

Is there a function available that can do this?

+3  A: 

You can do:

ob_start();
require 'some_script.php';
$html = ob_get_clean();

and then you have the output of the script.

If you need to call a URL, you can do this with cURL or alternatively you can use fopen()/fread() with a URL if that option is enabled in your PHP setup. I think the option is called allow_url_fopen or something similar.

$handle = fopen("http://www.example.com/", "r");
$output = fread($bundle, 20000);
cletus
Using output buffering is definitely the best way to go if it's on your own server... Less overhead and memory usage than a combination of fopen/fread.
BraedenP
Exactly what I was looking for, works perfect, thanks!
ticallian
Just wanted to point out that ob_start() can accept a callback argument, which may save you a few lines of code.
Adam Backstrom