Re: Code contents of a function

From: Date: Fri, 03 Jan 2003 10:07:13 +0000
Subject: Re: Code contents of a function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-130076@lists.php.net to get a copy of this message
Output buffering functions sound like something you could use: <?php function OtherStuff() { echo "MONKEY!!!<br>\n"; } function DoStuff() { echo "Something<br>\n"; echo "Something else<br>\n"; OtherStuff(); } // Start output buffering. ob_start(); // Grab the content. DoStuff(); $content = ob_get_contents(); // Finish up. ob_end_clean(); // What to do with $content? echo "Content is: <b>" . $content . "</b>\n"; ?> However, this could get messy and might not be what you're really after. If you're just wanting to return values from your functions, use return: function OtherStuff() { return "Monkey!<br>\n"; } function DoStuff() { $output = "Something<br>\n"; $output .= "Something else<br>\n"; $output .= OtherStuff(); return $output; } $content = DoStuff(); echo "Content = " . $content; would have a similar effect to the output method above. Anyway, further reference for you on output buffering can be found here: http://www.php.net/manual/en/ref.outcontrol.php -James "Shawn McKenzie" <nospam@mckenzies.net> wrote in message news:20030103011755.98000.qmail@pb1.pair.com... > I have a script with some functions and within the script I want to read the > code from one of the functions into a string. > > Example: > > function myfunction() { > echo "something"; > echo "something else"; > someotherfunction(); > } > > I want to read: > > echo "something"; > echo "something else"; > someotherfunction(); > > into a string. > > Any ideas??? TIA > -Shawn > >

« previous php.general (#130076) next »