Re: and newlines under windows

From: Date: Fri, 10 Aug 2007 23:27:39 +0000
Subject: Re: and newlines under windows
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-260653@lists.php.net to get a copy of this message
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?

« previous php.general (#260653) next »