str_replace with search and replace arrays
Posted: Fri Feb 09, 2007 8:41 pm
The current PHP manual gives the following example for str_replace:
That's great. However, a copy of the manual that I downloaded in October 2005 does not contain this example, and doesn't mention order of replacement. So my question is: has str_replace always had this behaviour?
Code: Select all
// 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);