preg_match / ereg and the null byte
| From: | Steven Fletcher | Date: | Mon, 24 Jul 2000 13:55:42 +0000 |
| Subject: | preg_match / ereg and the null byte | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-7864@lists.php.net to get a copy of this message | ||
Hi all;
Does anyone know why preg_match() or ereg() both seem to die, somewhat, when
they receive a byte of value 0x00? I have a snippet of code that goes like:
<?
$string = pack("H*", "52616e646f6d4956cf4a88446ea3c6e1");
#ereg("^RandomIV(.{2})(.*)$", $string, $match);
preg_match("/^RandomIV(.{2})(.*)$/", $string, $match);
echo "2 bytes go: ".($match[1])."\n\n";
echo "6 bytes go: ".($match[2])."\n\n";
?>
So, (please forgive the horrible text), $match[1] is "ÏJ" and $match[2]
becomes "^Dn£Æá", which is expected and works fine. However, if I change
$string to be:
pack("H*", "52616e646f6d4956cf4a88446e00c6e1"); -- (the A3, 3rd byte from
the end, is changed to a 00)
Then $match[1] remains the same, ie. "ÏJ", but $match[2] becomes "^Dn" - the
last 3 bytes (or whatever appeared after the 0x00 (as well as the 0x00
itself) are snipped from the end of the string.
Is there something that'll explain this, or some other way around the
problem? The process needs to work with data containing the null byte,
unfortunatley I can't just snip it out.
Thanks for any help anyone can provide!
Steven Fletcher
stevenf@shellnet.co.uk