Re: Loading a File into Variable - How??
| From: | Monty | Date: | Fri, 19 Jul 2002 04:22:16 +0000 |
| Subject: | Re: Loading a File into Variable - How?? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-108425@lists.php.net to get a copy of this message | ||
Hi Rasmus,
file_gets_contents() doesn't work in my version of PHP (4.2.1). It says "not
a valid function" or something like that. Also, I discovered that the
filesize() function won't work on files fopened from the include_path. It
returns a value of zero, so, I had to hardcode the bytes into the fread().
> From: rasmus@php.net (Rasmus Lerdorf)
> Newsgroups: php.general
> Date: Thu, 18 Jul 2002 15:14:13 -0700 (PDT)
> To: Analysis & Solutions <danielc@analysisandsolutions.com>
> Cc: PHP List <php-general@lists.php.net>
> Subject: Re: [PHP] Loading a File into Variable - How??
>
> In 4.3 you would use file_get_contents()
>
> In prior versions I would suggest:
>
> $fp = fopen('filename','r');
> $string = fread($fp, filesize('filename'));
> fclose($fp);
>
> The implode(file()) stuff is very memory-inefficient.
>
> -Rasmus
>