note 103633 deleted from function.pack by danbrown
| From: | danbrown@php.net | Date: | Mon, 25 Apr 2011 14:56:08 +0000 |
| Subject: | note 103633 deleted from function.pack by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-179120@lists.php.net to get a copy of this message | ||
Note Submitter: David Gero dave at havidave dot com
----
You might find these functions useful:
<?php
function byteStr2byteArray($s) {
return array_slice(unpack("C*", "\0".$s), 1);
}
function byteArray2byteStr(array $t) {
return call_user_func_array(pack, array_merge(array("C*"), $t));
}
function lsbStr2ushortArray($s) {
return array_slice(unpack("v*", "\0\0".$s), 1);
}
function ushortArray2lsbStr(array $t) {
return call_user_func_array(pack, array_merge(array("v*"), $t));
}
function lsbStr2ulongArray($s) {
return array_slice(unpack("V*", "\0\0\0\0".$s), 1);
}
function ulongArray2lsbStr(array $t) {
return call_user_func_array(pack, array_merge(array("V*"), $t));
}
?>
Of course, you can address byte strings as if they're arrays with numerical indexes, but the
other functions are helpful.