note 54748 deleted from function.str-replace by nlopess

From: Date: Mon, 08 Aug 2005 08:18:34 +0000
Subject: note 54748 deleted from function.str-replace by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-93232@lists.php.net to get a copy of this message
Note Submitter: mishagale ISNOTAT fastmail FULLSTOP fm ---- If you need to strip out newlines, then using a single str_replace() call is not portable, due to the difference between DOS/Win32, Mac and UNIX conventions. For portability try something like: <?php $x = 'My name is fred'; $x = str_replace("\n", "", $x); //UNIX $x = str_replace("\r\n", "", $x); //DOS $x = str_replace("\r", "", $x); //MAC ?> Alternativley, do it in one line with preg_replace: <?php $x = preg_replace('/\n|\r|(\r\n)/m', '', $x); ?> Apologies if someone already pointed this out.

« previous php.notes (#93232) next »