Created
December 4, 2009 12:56
-
-
Save dataich/249010 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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