Possible Duplicate:
capturing echo into a variable
I have a function that echos a string. Is their any way (besides altering the function) that I can negate the echo statement?
example:
function echo_string(){
echo "This is a string";
}
$dont_echo = negate_echo(echo_string());
$dont_echo .= ", 开发者_JS百科a negated string";
echo $dont_echo; // "This is a string, a negated string";
Is their anything like negate_echo
?
ob_start();
echo_string();
$buffer = ob_get_clean();
That is: Starting a new output buffer, execute the function, get the buffers content and close it. See ob_get_clean
Docs.
The only way is to use output buffering:
ob_start();
echo_string();
$output = ob_get_clean();
echo $output.", a negated string";
精彩评论