Is it possible to add the output of print() to a variable?
I have the following situation:
I have a php file which looks something like this:
You can use output buffering to capture any output send ob_start() http://us3.php.net/ob_start. You capture the output with ob_get_flush() http://us3.php.net/manual/en/function.ob-get-flush.php.
Or you could just return the output from title.php like so:
<?php
$content = '<h1>Page heading</h1>';
return $content;
You can capture output with the ob_start() and ob_get_clean() functions:
ob_start();
print("abc");
$output = ob_get_clean();
// $output contains everything outputed between ob_start() and ob_get_clean()
Alternatively, note that you can also return values from an included file, like from functions:
a.php:
return "<html>";
b.php:
$html = include "a.php"; // $html will contain "<html>"