|  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: None
 [2006-11-24 16:14 UTC] ivb at is dot ua
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:
$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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-24 21:59 UTC]
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
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 24 01:01:28 2024 UTC