note 86339 deleted from function.str-replace by danbrown

From: Date: Tue, 14 Oct 2008 03:02:13 +0000
Subject: note 86339 deleted from function.str-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-145333@lists.php.net to get a copy of this message
Note Submitter: Ottergoose ---- While this is a good example: <?php // Order of replacement $str = "Line 1\nLine 2\rLine 3\r\nLine 4\n"; $order = array("\r\n", "\n", "\r"); $replace = '<br />'; // Processes \r\n's first so they aren't converted twice. $newstr = str_replace($order, $replace, $str); ?> It would be more proper to use nl2br(): <?php $str = "Line 1\nLine 2\rLine 3\r\nLine 4\n"; $newstr = nl2br($str); ?>

« previous php.notes (#145333) next »