Can't seem to remove line break..

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

    Can't seem to remove line break..

    Hello all,

    In my PHP script I put a text file into a string. Part of that string is
    read, changed and removed. The while loop continuest to extract the next
    part of the string. This goes all fine with one exception. When there is a
    line break in the second string that has the extract of the first string, it
    cannot find the words I am looking for as it stops looking when it hits the
    line break.

    For example:

    string = why is that line break there
    string2 = that line
    break

    I am looking for "that line break", it can't find it with stristr.


    Which function can I use on the second string to have the line break
    removed?

    Thanks a lot in advance.

    Botak


  • Richard Podsada

    #2
    Re: Can't seem to remove line break..

    "Roland Dalmulder" <rdalmulderno@s pamhotmail.com> wrote in
    news:Y0Q1b.1198 82$0u.5993461@a msnews03.chello .com:
    [color=blue]
    > Hello all,
    >
    > In my PHP script I put a text file into a string. Part of that string
    > is read, changed and removed. The while loop continuest to extract the
    > next part of the string. This goes all fine with one exception. When
    > there is a line break in the second string that has the extract of the
    > first string, it cannot find the words I am looking for as it stops
    > looking when it hits the line break.
    >
    > For example:
    >
    > string = why is that line break there
    > string2 = that line
    > break
    >
    > I am looking for "that line break", it can't find it with stristr.
    >
    > Which function can I use on the second string to have the line break
    > removed?[/color]

    I assume you're writing to your text file line by line when you save it
    right? Are you appending \n after each line?

    What's probably happening is when you read it back in, you're not
    stripping the \n's out before working with your strings.

    You do your string thing and then write the file back to disk - adding
    *another* set of \n's.

    Read it in, add more \n's.. pretty soon you'll have a VERY easy to read
    document. Page and a half line spacing!

    While your reading in your text file (or going through the array created
    by file(), etc), strip out the CRLF's:

    $string = str_replace("\r ", "", $string);
    $string = str_replace("\n ", "", $string);

    --
    Richard


    Comment

    Working...