PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
// 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);
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?
Thanks. But what about the "order of replacement" functionality -- i.e., the guarantee that the array elements are processed in order -- has that been in place since 4.0.5?
The manual does not mention any change of behavior to that effect, so I would assume so. Remember: array('replace1', 'replace2', 'replace3') is equivalent to array(0 => 'replace1', 1 => 'replace2', 2 => 'replace3')