how to turn the output of a require statement into a string in php -
how to turn the output of a require statement into a string in php -
im working big team, , im making functions homecoming html code, , im echoing result of functions final page. thing is, need scrap of code developed other fellow member of team, , need string, code available php file im supposed include or require within page.
since im not writing ht;ml page, function generate code, need turn resulting html of require statement string concatenate code generated function.
is there way evaluate require , concatenate result strings?
ive tried function eval(), didnt work, , read thing get_the_content(), isnt working either. dont know if need import something, think have wordpress, , im using raw php.
thanks help!!! =)
try ob_...() family of functions. example:
<?php function f(){ echo 'foo'; } //start buffering output. output sent internal buffer instead of browser. ob_start(); //call function echos stuff f(); //save current buffer contents variable $foo = ob_get_clean(); echo 'bar'; echo $foo; //result: barfoo ?>
if want set echo'd result of include variable, this:
//untested function get_include($file){ ob_start(); include($file); homecoming ob_get_clean(); }
or if want set echo'd result of function phone call variable, this:
//untested //signature: get_from_function(callback $function, [mixed $param1, [mixed $param2, ... ]]) function get_from_function($function){ $args = func_get_args(); shift($args); ob_start(); call_user_func_array($function,$args); homecoming ob_get_clean(); }
php require
Comments
Post a Comment