#39621 [Opn->Csd]: str_replace() operates wrong on strings containing chr(0)

From: Date: Fri, 24 Nov 2006 21:59:14 +0000
Subject: #39621 [Opn->Csd]: str_replace() operates wrong on strings containing chr(0)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-105428@lists.php.net to get a copy of this message
ID: 39621 Updated by: tony2001@php.net Reported By: ivb at is dot ua -Status: Open +Status: Closed Bug Type: Strings related Operating System: Windows XP PHP Version: 5.2.0 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2006-11-24 16:14:32] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=39621&edit=1

« previous php.bugs (#105428) next »