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

Removing newline characters

P: n/a
How would you remove newline characters from a string?

I tried

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

But that doesn't work.

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
you also need to remove \r from the string.
(on windows, newline is \r\n, on *nix it's just \n, but a windows client
will send \r\n, and on older macs I think newline was just \r but I can't
remember for sure.)
"Amit Varia" <sp**@amitvaria.com> wrote in message
news:bu**********@geraldo.cc.utexas.edu...
How would you remove newline characters from a string?

I tried

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

But that doesn't work.

Jul 17 '05 #2

P: n/a
"Amit Varia" <sp**@amitvaria.com> wrote in message
news:bu**********@geraldo.cc.utexas.edu...
How would you remove newline characters from a string?

I tried

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

But that doesn't work.


as was posted there is also the \r on some files or \r\n, try this:

// for end of line (or begining)
$string = trim($string);

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

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.