php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36049 str_replace with arrays
Submitted: 2006-01-17 13:38 UTC Modified: 2006-01-17 13:41 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: Jared dot Williams1 at ntlworld dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.1.2 OS: Win2000
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: Jared dot Williams1 at ntlworld dot com
New email:
PHP Version: OS:

 

 [2006-01-17 13:38 UTC] Jared dot Williams1 at ntlworld dot com
Description:
------------
str_replace() not replacing entire search string with its replacement.

Reproduce code:
---------------
<?php
$s = array (
  0 => '%host', 1 => '%login',
  2 => '%user', 3 => '%time',
  4 => '%method', 5 => '%url',
  6 => '%protocol', 7 => '%status',
  8 => '%bytesSent', 9 => '%referrer',
  10 => '%userAgent',
);
$r = array (
  0 => '([^ ])+', 1 => '([^ ])+', 
  2 => '([^ ])+', 3 => '([^\\]])+',
  4 => '([^ ])+', 5 => '([^ ])+',
  6 => '([^"])+', 7 => '([^ ])+',
  8 => '([^ ])+', 9 => '([^"])+',
  10 => '([^"])+',
);
$subject = '%host %login %user [%time] "%method %url %protocol" %status %bytesSent "%referrer" "%userAgent"';

echo str_replace($s, $r, $subject), "\n";

Expected result:
----------------
([^ ])+ ([^ ])+ ([^ ])+ [([^\]])+] "([^ ])+ ([^ ])+ ([^"])+" ([^ ])+ ([^ ])+ "([^"])+" "([^ ])+"

Actual result:
--------------
([^ ])+ ([^ ])+ ([^ ])+ [([^\]])+] "([^ ])+ ([^ ])+ ([^"])+" ([^ ])+ ([^ ])+ "([^"])+" "([^ ])+Agent" 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-17 13:41 UTC] Jared dot Williams1 at ntlworld dot com
Err, my mistake
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 10:01:29 2024 UTC