Re: fread() question
| From: | Hans H. Anderson | Date: | Thu, 10 Aug 2000 02:04:32 +0000 |
| Subject: | Re: fread() question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-11052@lists.php.net to get a copy of this message | ||
file() reads each line to an array, so
$a = file("file.txt");
$a[0] is the first line.
Also, fgets would work, instead of fread, as it reads a line to the
newline character or the specified bytes, whichever comes first. This
would be more efficient, as you wouldn't have to drag the whole file into
an array just to read one line.
But, I don't see the necessity. If you want the whole file, this is the
easiest/best way:
$fp = fopen("file.txt","r");
$contents = fread($fp,filesize("file.txt"));
fclose($fp);
$contents has the whole file.
Hans
On Wed, 9 Aug 2000, CDitty wrote:
> I have a multilined textile that I want emailed to me every time the script
> is run. The only problem is that each line is different sizes. If I use
> fread(), I have to specify the number of chars to read. Does anyone know
> of a way to have it read to end of line? I looked through my manual and
> didn't see anything. Below is an example of the text file I am reading.
>
> mysqld ended on Wed Aug 9 09:54:39 MDT 2000
> mysqld started on Wed Aug 9 09:58:54 MDT 2000
> /usr/local/libexec/mysqld: ready for connections
> mysqld ended on Wed Aug 9 16:14:01 MDT 2000
> mysqld started on Wed Aug 9 16:15:49 MDT 2000
> /usr/local/libexec/mysqld: ready for connections
> 000809 19:41:50 /usr/local/libexec/mysqld: Normal shutdown
>
> Thanks
>
> CDitty
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>
>
Hans Anderson ~ me@hansanderson.com
PO Box 426, Missoula, MT 59806 | PHP, Search Engines, SQL
(800)397-9116 / (406)549-6524 | Databases, Flash Multimedia,
http://www.hansanderson.com | Killer Audio Production,
http://www.goofiness.com | Minty Fresh Breath.