str_replace binary safe??

From: Date: Mon, 22 Oct 2001 20:09:50 +0000
Subject: str_replace binary safe??
Groups: php.general 
Request: Send a blank email to php-general+get-71864@lists.php.net to get a copy of this message
Hi folks, following problem appeared on PHP 3.0.16 on LINUX I have a binary file, where I want to replace some letters I do the following: $filename = "xyz.sdc"; $fd = fopen( $filename, "r+b" ); // also tried "r" $x=filesize( $filename ); // this shows the correct filesize 22528 byte $contents = fread( $fd, $x ); fclose( $fd ); $y=strlen($contents); // The first mistake $y = 32956 byte echo "BEFORE<br>".$contents; $contents=str_replace("UUUUUU","123456", $contents); echo "AFTER<br>".$contents; It seems, that php converts HEX 00 00 to HEX 5C 30 just when it reads the data in memory because at the BEFORE echo the data will be shown as \0 (hex 00 00 ). The filesize will be correct when I save the str_replaced text and the text will be cahnged correct. Any idea, where this comes from?? Thanks in advance Oliver

« previous php.general (#71864) next »