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: 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: ivb at is dot ua
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Mon Apr 07 15:01:31 2025 UTC