php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61294 str_replace : array("\n", "\r") isn't working ; array('\n', '\r') is.
Submitted: 2012-03-05 21:58 UTC Modified: 2012-03-15 01:14 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: jean-baptiste dot renard at devsuitup dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.3.10 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jean-baptiste dot renard at devsuitup dot com
New email:
PHP Version: OS:

 

 [2012-03-05 21:58 UTC] jean-baptiste dot renard at devsuitup dot com
Description:
------------
---
From manual page: http://www.php.net/function.str-replace
---

In the featured example we have : 

$str     = "Line 1\nLine 2\rLine 3\r\nLine 4\n";
$order   = array("\r\n", "\n", "\r");
$replace = '<br />';

// Traitement du premier \r\n, ils ne seront pas convertis deux fois.
$newstr = str_replace($order, $replace, $str);


But I found than using this double quote syntax, \n where being displayed, at least not replaced.

By using simple quotes, this does work (like I was expecting at least :D)


Thanks you for your time guys, PHP rule !



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-05 21:59 UTC] jean-baptiste dot renard at devsuitup dot com
-Summary: array("\n", "\r") isn't working ; array('\n', '\r') is. +Summary: str_replace : array("\n", "\r") isn't working ; array('\n', '\r') is.
 [2012-03-05 21:59 UTC] jean-baptiste dot renard at devsuitup dot com
Summary change : more accurate.
 [2012-03-15 01:14 UTC] dtajchreber@php.net
Manual example works as expected:

http://codepad.org/L2mEjtZv

Perhaps you're viewing the output in a browser and missing something? But there's 
no mistake here...
 [2012-03-15 01:14 UTC] dtajchreber@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 11:00:02 2026 UTC