日期:2014-05-17 浏览次数:20837 次
//A字符 $str = (pack ( "A*", "中国" )); echo $str, "=", strlen ( $str ), "字节\n"; getAscill ( $str ); echo '<br/>'; //H字符 $str = (pack ( "H*", "fffe" )); echo $str, "=", strlen ( $str ), "字节\n"; getAscill ( $str ); echo '<br/>'; //C字符 $str = (pack ( "C*", "55", "56", "57" )); echo $str, "=", strlen ( $str ), "字节\n"; getAscill ( $str ); echo '<br/>'; //i字符 短整形 32位 4个字节 64位8个字节 $str = (pack ( "i", "100" )); echo $str, "=", strlen ( $str ), "字节\n"; getAscill ( $str ); echo '<br/>'; //s字符 短整形 2个字节 $str = (pack ( "s", "100" )); echo $str, "=", strlen ( $str ), "字节\n"; getAscill ( $str ); echo '<br/>'; //l字符 长整形 4个字节 $str = (pack ( "l", "100" )); echo $str, "=", strlen ( $str ), "字节\n"; getAscill ( $str ); echo '<br/>'; //f字符 单精度浮点 4个字节 $str = (pack ( "f", "100" )); echo $str, "=", strlen ( $str ), "字节\n"; getAscill ( $str ); echo '<br/>'; //d字符 双精度浮点 8个字节 $str = (pack ( "d", "100" )); echo $str, "=", strlen ( $str ), "字节\n"; getAscill ( $str ); echo '<br/>'; function getAscill($str) { $arr = str_split ( $str ); foreach ( $arr as $v ) { echo $v, "=", ord ( $v ), "\n"; } echo "=============\r\n\r\n"; }
$code=array( "username"=>array("A20","张三adfb12"), "pass"=>array("A10","asdf*#1"), "age"=>array("C","23"), "birthday"=>array("I","19900101"), "email"=>array("A50","zhangsan@163.com")); $stream=join("\0",packByArr($code)); echo $stream,strlen($stream); file_put_contents("c:/1.txt",$stream); //将流保存起来便于下面读取 function packByArr($arr) { $atArr=array(); foreach ($arr as $k=>$v) { $atArr[]=pack($v[0],$v[1]); } return $atArr; } function getAscill($str) { $arr=str_split($str); foreach ($arr as $v) { echo $v,"=",ord($v),"\n"; } }
$code=array( "username"=>array("A20"), "pass"=>array("A10"), "age"=>array("C"), "birthday"=>array("I"), "email"=>array("A50"));