I've been designing a new theme for the blog (using WordPress 1.3), and in doing so ran into a problem where some of the WordPress supplied functions printed instead of returning the string I was interested in. One example is the comment_author() function, which prints (using echo) the author of a particular comment. I did a bit of research and eventually found a way to "redirect" the output into a variable, so I could use it in the other code.
Note: I know very little about PHP, so this is probably a very kludgy, very ineffective hack. If anyone can suggest a better solution, I'll listen!
Hopefully someone will find this of use…
Thanks to this article, I found out that you can use output buffering in PHP to "collect" anything printed or echoed and save it for later use.
My aim was to get the output of the comment_author() function, and then use it in an if () statement to check if the author was me.
Here's the code I used, with explanations in the comments:
<?php
/* We want to find out who the author is, but not
echo it. */
// Start output buffering
ob_start();
// Run the function echoing the output
comment_author();
// Assign a variable to the contents of the buffer
$author = ob_get_contents();
// Close the buffer and clean it
ob_end_clean();
// Set the default value
$jeremy = 0;
// Check if the returned author was me
if ($author == 'Jeremy Higgs') {
$jeremy = 1;
}
?>
… and that's that! The output from the comment_author() function is saved to the $author variable, for later use!

Funny, I was searching for a solution to this same problem, as I am also designing a Wordpress theme and wanted to customize some of the output.
I tried creating a plug-in using the old functions as templates, but I ran into a few MySQL errors for some reason. I’m not familiar enough with PHP to figure out that the problem was, so capturing the echoed output was the trick I needed. Thanks for posting this.
No problems…! I’m glad the tip was of use to you.
I also was looking for a solution to this… your page is the top of the list when i googled it.. Anyhow, thanx for saving me some time
Cheers.
I concur with su-Root … thank you for the offered solution! You saved me a lot of time
Very helpful, thanks! Strange that the PHP documentation doesn’t offer any similar help.
Actually PHP documentation offer almost everything. But unfortunately, in most cases it is not ‘cut-n-paste’ code but material to think about.
Thanks Jeremy.
Sorry, posted the previous comment in the wrong blog. Please ignore this.
The correct address for this comment should be:
http://codeutopia.net/blog/2007/10/03/how-to-easily-redirect-php-output-to-a-file/
The article solves a similiar problem with the help of the ob_xxxx output buffer functions.
MANY, MANY THANKS FOR SHARING THIS!
Thanks a lot man! It is of great help to me in customizing a wordpress theme.
I was in need of this to translate the output of wordpress functions to my lanugage, Tamil (which is not yet completely supported)
Thank you very much, this is very very useful for hacking Wordpress.
Cheers!