RE: [PHP] working with files
| From: | Gryffyn, Trevor | Date: | Wed, 28 Jan 2004 22:10:21 +0000 |
| Subject: | RE: [PHP] working with files | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-176133@lists.php.net to get a copy of this message | ||
Depending on what system you're using, the EOL (end of line) character
is going to be different.
On a DOS/Windows system, you want to use "\r\n".
I can't remember off the top of my head now, but some systems use just
"\r" and some use just "\n".. DOS/Windows systems use both, and I
believe they need to be in \r\n order, not \n\r.
If you're not sure if you're saving them properly, load the text file
into Notepad and you'll see a weird square character show up if the line
break (EOL) character(s) is wrong.
Maybe I'm lazy or uneducated, but I like to just use file() when I'm
reading a text file. It loads everything into an array that has the
line number and then the entire line, stripping off the \r\n's for you.
Hope this helps a little!
-TG
> -----Original Message-----
> From: tony [mailto:awardd@essex.ac.uk]
> Sent: Wednesday, January 28, 2004 1:53 PM
> To: php-general@lists.php.net
> Subject: [PHP] working with files
>
>
> hi,
>
> i have problem with writing a reading to file
> i want to write emails in files. like this
> email1@email1.com
> email2@email2.com
> email3@email3.com
> etc......
>
> this is how I write to the file
>
> $handle = fopen($filename, "a");
> fwrite($handle,"$email\n",128);
> fclose($handle);
>
>
> ok it writes everything just fine but now i want to read the
> file line by
> line and print line by line.
> this is how i do it.
>
> <?php
> $handle = fopen ($filename, "r");
>
> do {
> $data = fread($handle, 128);
> if (strlen($data) == 0) {
> break;
> }
> print ("$data<br>");
> } while (true);
> fclose($handle);
> ?>
>
>
>
> the problem i get then is everything is printed in one line.
>
>
>
> any help is appreciated.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>