note 8085 modified in function.fread by aidan

From: Date: Thu, 01 Jul 2004 08:47:57 +0000
Subject: note 8085 modified in function.fread by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72245@lists.php.net to get a copy of this message
Fread is binary-safe IF AND ONLY IF you don't use magic-quotes. If you do, all null bytes will become \0, and you might get surprising results when unpacking. That is, you would do something like <?php set_magic_quotes_runtime(0); ?> before fread() and something like <?php set_magic_quotes_runtime(get_magic_quotes_gpc()) after. ?> And, after fread, an unpack would be needed, of course. Surprisingly, pack(), however, does not work quite like in Perl (or perhaps I'm just missing something here) - you can't pack an array directly, but instead you'll have to pack each element seperately to the string: <?php foreach ($data as $dec) { $data_output .= pack("C*", $dec); } ?> --was-- Fread is binary-safe IF AND ONLY IF you don't use magic-quotes. If you do, all null bytes will become \0, and you might get surprising results when unpacking. That is, you would do something like set_magic_quotes_runtime(0); before fread() and something like set_magic_quotes_runtime(get_magic_quotes_gpc()) after. And, after fread, an unpack would be needed, of course. Surprisingly, pack(), however, does not work quite like in Perl (or perhaps I'm just missing something here) - you can't pack an array directly, but instead you'll have to pack each element seperately to the string: foreach ($data as $dec) { $data_output .= pack("C*", $dec); } http://php.net/manual/en/function.fread.php

« previous php.notes (#72245) next »