i am sorry for the triple post, i truly am... but i solved this issue after a day's work of googling and thought i could save people the same trouble by posting my solution here. i guess a moderator could delete by past two posts or something.
any way...
i discovered the use of buffering data before it reaches the browser.
<?php
//function that gets html
function getHTML($container_function){
//johndm.com - gets html that results from
//a function. example usage:
// <?php function foo(){ ?|> bar <?php } ?|>
// echo "<b>".getHTML("foo")."</b>";
ob_start();ob_clean(); //start buffer
call_user_func($container_function); //call container function
$data=ob_get_contents(); //get data
ob_end_clean(); //remove output from function
return $data; //return html
}
//example usage
function foo(){ ?>
<b>foo</b>
<?php }
$d=getHTML("foo");
//now that the html outputted by the
//function is in a string, you can do anything
//to it you could do to a string.
echo "i am a ".$d." bar";
echo "<br />";
echo "i am ".strlen($d)." chars long";
echo "<br />";
echo "i have ".substr_count($d,">")." '>'s in me";
echo "<br />";
echo "my html looks like this: ".htmlentities($d);
//not only can it get html that is not inside
//of php tags, it can also let you modify
//echo/printed data from a function also.
?>
Last edited by hunkychop : Mar 28th, 2008 at 8:09 pm.
toast