Thursday, August 25, 2005

PHP Script to variable

The following I found on a Usenet post on how to EASILY parse a PHP script’s output to a variable using output buffering:

"Daniel Loose" <nore...@web.de> kirjoitti viestissä:430cb793.9399...@news.cs.tu-berlin.de...
> Hello,
> I have this strange including problem:
> I want to read a piece of HTML, residing in some file, into a > variable, not echo it out. So far so easy - but now the HTML contains > a line of PHP. And I wish not to get the PHP code into my variable but > the parsed result, just like if the variable was a client ;-). I wish > to keep the nice ?> ...<? HTML area (with highlighting in my editor), > and therefore include etc. don't help because they would echo it out. > heredoc also doesnt help (if this may come up to your mind).
> Is there anything I can do...?!! The problem sounds so simple... the > more for such a great tool like PHP ... but... ?!!

Sounds like you could use buffering.

ob_start(); // Start output buffering.
// Instead of outputting anything, the output is now stored in a buffer.
include('yourfile.php');
// There, now the file has been included and php parsed.
// It isn't output, it goes into the buffer.
$yourfile = ob_get_clean();
// Now we read everything that has been buffered... And stops buffering.
?>



Result: the file you included has been parsed by the php engine and stored inside $yourfil, and nothing was output. Sounds like goal achieved.
-- SETI @ Home - Donate your cpu's idle time to science. Further reading at <http://setiweb.ssl.berkeley.ed u/> Kimmo Laine <eternal.erectio...@5P4Mgmail.com>

3 Comments:

Blogger shawnwarner5812 said...

i thought your blog was cool and i think you may like this cool Website. now just Click Here

10:13 AM  
Blogger tavon75nichole said...

Are you stuck in a job that is leading you on the path to no where?
We can help you obtain a College Degree with classes, books, and exams
Get a Genuine College Degree in 2 Weeks!
Well now you can get them!

Call this number now 24 hours a day 7 days a week (413) 208-3069

Get these Degrees NOW!!!

BA, BSc, MA, MSc, MBA, PHD,

Within 2 weeks!
No Study Required!
100% Verifiable

Call this number now 24 hours a day 7 days a week (413) 208-3069

These are real, genuine, They are verifiable and student records and
transcripts are also available. This little known secret has been
kept quiet for years. The opportunity exists due to a legal loophole
allowing some established colleges to award degrees at their discretion.

With all of the attention that this news has been generating, I wouldn't
be surprised to see this loophole closed very soon.

Get yours now, you will thank me later!
Call this number now (413) 208-3069
We accept calls 24 hours a day 7 days a week.

2:05 PM  
Blogger joeytheo07448447 said...

hey, I just got a free $500.00 Gift Card. you can redeem yours at Abercrombie & Fitch All you have to do to get yours is Click Here to get a $500 free gift card for your backtoschool wardrobe

10:37 AM  

Post a Comment

<< Home