PHP 8.5.0 Alpha 1 available for testing

Voting

: five plus four?
(Example: nine)

The Note You're Voting On

Anonymous
15 years ago
Functions I found useful when dealing with fixed width file processing, related to unpack/pack functions.
<?php
/**
* funpack
* format: array of key, length pairs
* data: string to unpack
*/
function funpack($format, $data){
foreach (
$format as $key => $len) {
$result[$key] = trim(substr($data, $pos, $len));
$pos+= $len;
}
return
$result;
}

/**
* fpack
* format: array of key, length pairs
* data: array of key, value pairs to pack
* pad: padding direction
*/
function fpack($format, $data, $pad = STR_PAD_RIGHT){
foreach (
$format as $key => $len){
$result .= substr(str_pad($data[$key], $len, $pad), 0, $len);
}
return
$result;
}
?>

<< Back to user notes page

To Top