Professional Web Applications Themes

Can't seem to remove line break.. - PHP Development

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

  1. #1

    Default 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


    Roland Dalmulder Guest

  2. #2

    Default Re: Can't seem to remove line break..

    "Roland Dalmulder" <rdalmuldernospamhotmail.com> wrote in
    news:Y0Q1b.119882$0u.5993461amsnews03.chello.com:
    > 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?
    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
    doent. 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


    Richard Podsada Guest

  3. #3

    Default Re: Can't seem to remove line break..

    The line breaks show up because of multi-byte encoding, I believe. Try:

    $newstring = mb_substr($string_w_line_break,[start],[length],'UTF-8');

    That worked for me when strange line breaks showed up after parsing html.
    solarnick Guest

Similar Threads

  1. How do I put line break in my asp page?
    By Aaron Bertrand - MVP in forum ASP
    Replies: 2
    Last Post: October 19th, 08:50 PM
  2. line break
    By cozzabags in forum Macromedia Contribute General Discussion
    Replies: 4
    Last Post: August 19th, 05:21 PM
  3. Forced line break changes previous line endings
    By Olav_Kvern@adobeforums.com in forum Adobe Indesign Macintosh
    Replies: 12
    Last Post: September 8th, 01:11 AM
  4. line break in a datagrid
    By hannes in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: March 13th, 01:48 PM
  5. Preventing Line Break
    By tjelen webforumsuser@macromedia.com in forum Macromedia Dynamic HTML
    Replies: 1
    Last Post: January 18th, 12:14 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139