a solution for parsing an external file into a variable

From: Date: Mon, 26 Jun 2000 23:15:05 +0000
Subject: a solution for parsing an external file into a variable
Groups: php.general 
Request: Send a blank email to php-general+get-3238@lists.php.net to get a copy of this message
There has been a lot of discussion on how to parse an external php file into a variable for use later in the script. If eval(), system(), include() or require() are used they automatically print text outside the <??> or in print() to the browser. Usually this not acceptable. So here is a solution if you are using PHP4. <? ob_start(); //start output buffering include ("table.php"); //all output goes to buffer $buf = ob_get_contents(); //assign buffer to a variable ob_end_clean(); //clear buffer and turn off output buffering print $buf; ?> You can use eval() or system() or required() instead of include(). Obviously, you don't want to immediately print out the buffer but send it another function for manipulation or output at a later time. I hope this helps all of you who are looking for a solution. Charles

« previous php.general (#3238) next »