RE: [PHP] break up variable and put each element in an array

From: Date: Sat, 12 Aug 2006 21:30:56 +0000
Subject: RE: [PHP] break up variable and put each element in an array
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-240574@lists.php.net to get a copy of this message
On Fri, August 11, 2006 2:40 am, Reinhart Viane wrote: > Actually, I know that it's browser/OS dependent, cuz I had a bunch of > Mac users who sent only \r all the time. > > This may be true only of OS 9, and you may not care about them > anymore, but there it is. > > I also would not be so quick to claim that Linux sends \r\n -- It > could be dependent on the browser, the OS version, the OS distro, some > OS settings, ... > > Better safe than sorry, and I *know* I ran into this with some Mac > users. > > Plus I hate trying to edit the text chunks in vi with those icky \r > thingies that turn into ^M :-) > > What would you suggest to use then? I would suggest using the code I posted that started this sub-thread... :-) //The order of operations is crucual here: $string = str_replace("\r\n", "\n", $string); $string = str_replace("\r", "\n", $string); You could use arrays for str_replace, and reduce the function calls, but that relies on the ORDER in which the array/substitutions are processed. While I can't imagine the array version of str_replace doing them in reverse order, it is not currently a documented behaviour, so I personally would just take the penalty of 2 function calls, unless it's a proven performance problem (which seems unlikely). YMMV -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#240574) next »