[wp-hackers] Returning instead of echoing
Alex King
alex at alexking.org
Sat Nov 6 20:59:35 UTC 2004
An easy way to get the echoed/printed content into a variable:
<?php
ob_start();
the_title();
$my_title = ob_get_contents();
ob_end_clean();
print($my_title);
?>
--Alex
http://www.alexking.org/
On Nov 6, 2004, at 1:46 PM, Michael Heilemann wrote:
> I've been wondering for some time now. In fact, ever since I started
> to learn a bit of PHP, so that I could write Kubrick
> (binarybonsai.com/kubrick), why on God's green Earth the majority of
> the functions in WordPress echo rather than return their results?
>
> I can't really come up with any particular reason for doing it this
> way, rather than simply returning the result for easy inline parsing
> if needed...
>
> The way it is now, when I for instance want to add a title="" to the
> comment link, I have to dig out the code somewhere inside the core of
> WordPress and change it. Which I can deal with... Until the next
> version rolls around and I have to deal with upgrading my hacked
> codebase.
>
> If instead comments_popup_link was divided into two seperate
> functions, one for fetching the URI, and one for fetching the number
> of comments, I could echo them out and do whatever the devil I wanted
> with them...
>
> Am I missing something?
>
> Aloha, Mike
> http://binarybonsai.com
>
>
> _______________________________________________
> hackers mailing list
> hackers at wordpress.org
> http://wordpress.org/mailman/listinfo/hackers_wordpress.org
More information about the hackers
mailing list