is fgets causing these line breaks

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am downloading data from a website that displays it in a table
        $fp = fopen("a website page", 'r');

The following accesses the stream one <td> element at a time
        $myData = fgets($fp);

Then I select the $myData that I want and add them to a string, $str1
                 $str1 = $str1.$myData;
                 $myData = fgets($fp);

then strip the html tags from the string
        $body = strip_tags($str1);

and use the resulting string as the body of an email

If I echo $body to the php page doing all this,  $body displays as a single
line with no line breaks.
However the resulting email displays $body as a series of lines
corresponding to those derived from $myData = fgets($fp).
Can someone please explain what is happening here?
Ideally I would like to be able format $body so the email lines break
differently to this.


Re: is fgets causing these line breaks

Bill wrote:
Quoted text here. Click to load it

fgets() returns a string with the newline attached!

You may want to trim() it before processing further:

    $myData = trim(fgets($fp));

Quoted text here. Click to load it

Line breaks do not show up in the browser. Check the HTML source and I'm
pretty sure you will find the line breaks there.

Quoted text here. Click to load it

The line breaks do show on mail bodies.
    [unless you send (bad) HTML mail]

Quoted text here. Click to load it

Hopefully you will be able to do it now.

Happy Coding :-)
USENET would be a better place if everybody read:    | to  mail  me:  simply |    | "reply" to this post, |      | *NO* MIME, plain text |                     | and *NO* attachments. |

Site Timeline