Re: and newlines under windows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, August 10, 2007 11:48 am, Faither wrote:
> I'm kind of lost with how str_replace , preg_replace, ereg_replace or
> even explode are handling a "\n"-ewline.
.
.
.
> Is it even possible under windows? ^^

In Linux, the newline is "\n", but...

Under Windows, the newline isn't "\n", it's "\r\n"

In the Mac world it's "\r"

Now the browsers are running on whatever platform, and the user is
copying/pasting in text or whatever, and the data you get PROBABLY is
using the newline encoding of the web browser client platform.

So, to normalize any input with newlines, do this:

//assuming basic ASCII text data input:
$data = str_replace("\r\n", "\n", $data);
$data = str_replace("\r", "\n", $data);

Store that normalized text in the database.

When you DISPLAY the text to the user, you might want to use:
echo nl2br($data);

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux