By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,361 Members | 1,677 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,361 IT Pros & Developers. It's quick & easy.

is fgets causing these line breaks

P: n/a
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
while(condition){
$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
mail($to,$subject,$body,$from)
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.

Thanks
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Bill wrote:
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);
fgets() returns a string with the newline attached!

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

$myData = trim(fgets($fp));
[snip] If I echo $body to the php page doing all this, $body displays as a single
line with no line breaks.
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.
However the resulting email displays $body as a series of lines
corresponding to those derived from $myData = fgets($fp).
The line breaks do show on mail bodies.
[unless you send (bad) HTML mail]
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.


Hopefully you will be able to do it now.

Happy Coding :-)
--
USENET would be a better place if everybody read: | to mail me: simply |
http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
http://www.expita.com/nomime.html | and *NO* attachments. |
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.