For Programmers: Free Programming Magazines  


Home > Archive > PHP Documentation > October 2006 > #38463 [Opn->Csd]: Order of replacement using array in str_replace not documented









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author #38463 [Opn->Csd]: Order of replacement using array in str_replace not documented
dave@php.net

2006-10-15, 3:56 am

ID: 38463
Updated by: dave@php.net
Reported By: IFokkema at Ileos dot nl
-Status: Open
+Status: Closed
Bug Type: Documentation problem
Operating System: All
PHP Version: Irrelevant
New Comment:

This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation
better.




Previous Comments:
------------------------------------------------------------------------

[2006-08-15 08:29:43] IFokkema at Ileos dot nl

Description:
------------
Hi guys,

After a discussion in the list, I've reread the manual page
(http://www.php.net/str_replace) and the comments, checked Google, but
need some confirmation.

When using an array as the search argument in str_replace(), the array
is processed first to last. As expected, but this behaviour is not
documented and therefor not reliable for my project.

$s = "Input\r\nMore input\rSome more\nEtc";
echo str_replace(array("\r\n", "\n", "\r"), '<BR>', $s);

This works as expected (putting exactly one <BR> between every line of
input). Related comment on the manual page is from "jr at adslate dot
com (03-Jun-2004 02:52)".

But since it's not documented, I can't rely on this. If the order of
replacement is ever switched, my code stops working properly.

Now I have to do this, to process all OS specific line breaks
correctly:
$s = str_replace("\r\n", "\n", $s);
$s = str_replace("\r", "\n", $s);
echo str_replace("\n", '<BR>', $s);

Can you guys please document the order of handling the search array?

Thanks a bunch for all of your work.



------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=38463&edit=1
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com