note 103555 added to function.str-replace

From: Date: Wed, 20 Apr 2011 11:16:16 +0000
Subject: note 103555 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-178987@lists.php.net to get a copy of this message
When using the following code from the example // 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); The \r\n won't get replaced. To get it to work change all occurrences of double quotes into single quotes so the code reads as follows. // 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); The code will then as expected. I just spent 20 minutes trying to get this code to work just to realise the quotes in the array are wrong. ---- Server IP: 69.147.83.197 Probable Submitter: 82.109.45.66 ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- https://master.php.net/note/edit/103555 Del: integrated -- https://master.php.net/note/delete/103555/integrated Del: useless -- https://master.php.net/note/delete/103555/useless Del: bad code -- https://master.php.net/note/delete/103555/bad+code Del: spam -- https://master.php.net/note/delete/103555/spam Del: non-english -- https://master.php.net/note/delete/103555/non-english Del: in docs -- https://master.php.net/note/delete/103555/in+docs Del: other reasons-- https://master.php.net/note/delete/103555 Reject -- https://master.php.net/note/reject/103555 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178987) next »