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

Can't seem to remove line break..

P: n/a
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
Jul 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Roland Dalmulder" <rd**********@spamhotmail.com> wrote in
news:Y0*********************@amsnews03.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
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
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.