RE: [PHP] Problems with file_get_contents() and local PHP file
| From: | Michael Kelly | Date: | Wed, 08 Aug 2007 18:58:09 +0000 |
| Subject: | RE: [PHP] Problems with file_get_contents() and local PHP file | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-260453@lists.php.net to get a copy of this message | ||
I'm too busy with other matters to try this out right now, but I'll make
sure to try it later when I can. Thanks!
-Mike
----- Original Message -----
From: ""Jan Reiter"" <the-fallen@gmx.net>
Newsgroups: php.general
To: <ceo@l-i-e.com>; "'Mike'" <zmen8@msn.com>
Cc: <php-general@lists.php.net>
Sent: Tuesday, August 07, 2007 11:01 PM
Subject: RE: [PHP] Problems with file_get_contents() and local PHP file
> D'oh!
>
> The solution is so simple and clean that it almost hurts. I didn't see it
in
> the first approach!
>
> There is a way to go all this, without using file() or
file_get_contents()!
> Cuz this would require to use a URL wrapper to retrieve compiled code,
which
> would cost overhead on the local webserver and the internet deamon.
>
> Just use and modify this code. You may also put it into a function;
>
>
> // I strongly recommend to use this INSIDE a function to get a clear
> namespace
> function get_img_script($parameters)
> {
>
> // backup $_GET variable
> $getbuffer = $_GET;
> unset($_GET);
>
> $_GET = $parameters;
>
> ob_start();
> include 'yourscript.php';
> $buffer = ob_get_contents();
> Ob_end_clean();
>
> // restore $_GET variable
> unset($_GET);
> $_GET = $getbuffer;
>
> return $buffer;
> }
>
> And call it like this:
>
> // define variables here. If you'd passed it with ?var=val
> // use
>
> $param = array('var'=>'val');
> $img = get_img_script($param);
>
>
> Hope that solves the problem in a clean way!
>
> Jan
>
>