Page 1 of 1

[SOLVED]Replace Carriage Returns?

Posted: Mon Apr 12, 2004 11:06 am
by webcan
Hello:

I have a variable, $text, that contains some carriage returns:

Line1
Line2
Line3
etc...

What do I do to replace the carriage returns in $text with something that can be sent in the QUERY_STRING? (eg. %20 for space, I dont know what it is for carriage return).

I tried doing it with str_replace, but this doesnt seem to replace anything:

$text = str_replace('\n', '%something', $text);

Thanks,
Peter.

Posted: Mon Apr 12, 2004 11:29 am
by lostboy

Posted: Mon Apr 12, 2004 12:02 pm
by webcan
OK, I did this:

$text = htmlentities($text);

And nothing happens - the $text variable is unchanged.

Why isn't this working?
And I'd like to figure out why the str_replace above didn't work either.

Thanks,
Peter.

Posted: Mon Apr 12, 2004 12:07 pm
by patrikG
If you're working under Windows linebreaks are usually "\r\n" hence you need to replace that. Under Unix linebreaks are a simple "\n".

Modify your str_replace there and it should work.

Posted: Mon Apr 12, 2004 12:15 pm
by webcan
Thank you!

That solved my str_replace problem.

Posted: Mon Apr 12, 2004 12:20 pm
by patrikG
:)

Posted: Mon Apr 12, 2004 3:40 pm
by Ixplodestuff8
Make sure to use both \r\n and \n, not just one or the other so it works no matter what system you're using.