is fgets causing these line breaks

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill

    is fgets causing these line breaks

    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($str 1);

    and use the resulting string as the body of an email
    mail($to,$subje ct,$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


  • Pedro Graca

    #2
    Re: is fgets causing these line breaks

    Bill wrote:[color=blue]
    > 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);[/color]

    fgets() returns a string with the newline attached!

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

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


    [snip][color=blue]
    > If I echo $body to the php page doing all this, $body displays as a single
    > line with no line breaks.[/color]

    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.
    [color=blue]
    > However the resulting email displays $body as a series of lines
    > corresponding to those derived from $myData = fgets($fp).[/color]

    The line breaks do show on mail bodies.
    [unless you send (bad) HTML mail]
    [color=blue]
    > 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.[/color]

    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. |

    Comment

    Working...