php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39621 str_replace() operates wrong on strings containing chr(0)
Submitted: 2006-11-24 16:14 UTC Modified: 2006-11-24 21:59 UTC
From: ivb at is dot ua Assigned:
Status: Closed Package: Strings related
PHP Version: 5.2.0 OS: Windows XP
Private report: No CVE-ID:
 [2006-11-24 16:14 UTC] ivb at is dot ua
Description:
------------
If 'search' and 'subject' has equal length and both begins with equal substring with chr(0) inside - str_replace() considers that 'search' and 'subject' equals.

Reproduce code:
---------------
<?php
$search =  "qx\0qqqqqqqqqq";
$subject = "qx\0xxxxxxxxxx";
$replace = "any text";

$result = str_replace ( $search, $replace, $subject );

echo $search . "\n" . $replace . "\n" . $subject . "\n" . $result . "\n";
?>

Expected result:
----------------
qx qqqqqqqqqq
any text
qx xxxxxxxxxx
qx xxxxxxxxxx

Actual result:
--------------
qx qqqqqqqqqq
any text
qx xxxxxxxxxx
any text

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-24 21:59 UTC] tony2001@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sat Apr 19 22:02:16 2014 UTC