note 103634 added to function.unpack
| From: | DavidGerodave at havidave dot com | Date: | Mon, 25 Apr 2011 14:50:13 +0000 |
| Subject: | note 103634 added to function.unpack | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179119@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 66.207.199.35
Probable Submitter: 173.33.54.15
----
Manual Page -- http://www.php.net/manual/en/function.unpack.php
Edit -- https://master.php.net/note/edit/103634
Del: integrated -- https://master.php.net/note/delete/103634/integrated
Del: useless -- https://master.php.net/note/delete/103634/useless
Del: bad code -- https://master.php.net/note/delete/103634/bad+code
Del: spam -- https://master.php.net/note/delete/103634/spam
Del: non-english -- https://master.php.net/note/delete/103634/non-english
Del: in docs -- https://master.php.net/note/delete/103634/in+docs
Del: other reasons-- https://master.php.net/note/delete/103634
Reject -- https://master.php.net/note/reject/103634
Search -- https://master.php.net/manage/user-notes.php