Writing Binary

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Everyone,
I'm trying to write a PHP script that opens a binary file, reads the binary in chunks, checks those chunks for a certain binary string, and then if the string is found, it replaces the string with another binary string. The script should then a copy of the file, including the changed bits. But for some reason, the script is not replacing the binary string.

Here's the source code:

<?php

$in = fopen("C:\NeighborhoodManager.package", "rb");
$out = fopen("C:\NeighborhoodManager2.package", "w");
$count = 0;

while (!feof($in)) {
 $count++;
 $buffer = fread($in,50000);
if (eregi("0101001101110100011100100110000101101110011001110110010101110100011011110111011101101110",$buffer))
 {
$buffer2=eregi_replace("0101001101110100011100100110000101101110011001110110010101110100011011110111011101101110","0101011001101001011000110111010001101111011100100110100101100001",$buffer);
 }
 else
 {
   $buffer2 = $buffer;
 }
 fwrite($out,$buffer2);
}
fclose($out);
fclose($in);
print("About ".($count*50000)." bytes read.\n");

?>

The resulting file is not changed at all, the size, md5 sums, and contents are the same as the original file. The original file is only 40,960 bytes on the disk, so the script reads the file in one pass. I am sure the binary string is in the original file, and I have tried reading the file into chunks as small as 64 bytes. I am at a loss as to what is happening, so I would appreciate any help.

Sincerely,
Philip W.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux