Reply to Re: Read *parsed* PHP file into a variable?

Your name:

Reply:


Posted by Kimmo Laine on 08/24/05 22:20

"Daniel Loose" <noreply@web.de> kirjoitti
viestissδ:430cb793.9399600@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.
<?php

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.edu/>
Kimmo Laine <eternal.erectionN0@5P4Mgmail.com>

[Back to original message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация