Skip to content

Instantly share code, notes, and snippets.

@dataich
Created December 4, 2009 12:56
Show Gist options
  • Save dataich/249010 to your computer and use it in GitHub Desktop.
Save dataich/249010 to your computer and use it in GitHub Desktop.
<?php
$str = "12345123456712"; //固定長テキスト
$lengths = array(5,7,2); //分割する長さの指定
$format = ''; //フォーマット
$cursor = 0; //カーソル位置のカウント
//フォーマットの作成
foreach($lengths as $length) {
if($cursor != 0) {
//PHPの場合、2番目以降は x数値 を使用して開始位置を指定する
$format .= "x$cursor/";
}
$format .= "A$length ";
$cursor += $length;
}
$outs = unpack($format, $str);
foreach ($outs as $out) {
print "$out ";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment