note 94810 modified in function.pack by danbrown

From: Date: Thu, 26 Nov 2009 18:18:34 +0000
Subject: note 94810 modified in function.pack by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-163314@lists.php.net to get a copy of this message
may be useful <?php public function unpack_str($str, $len) { $tmp_arr = unpack("c".$len."chars", $str); $out_str = ""; foreach($tmp_arr as $v) { if($v>0) { $out_str .= chr($v); } } return $out_str; } public function pack_str($str, $len) { $out_str = ""; for($i=0; $i<$len; $i++) { $out_str .= pack("c", ord(substr($str, $i, 1))); } return $out_str; } ?> --was-- may be useful public function unpack_str($str, $len) { $tmp_arr = unpack("c".$len."chars", $str); $out_str = ""; foreach($tmp_arr as $v) { if($v>0) { $out_str .= chr($v); } } return $out_str; } public function pack_str($str, $len) { $out_str = ""; for($i=0; $i<$len; $i++) { $out_str .= pack("c", ord(substr($str, $i, 1))); } return $out_str; } http://php.net/manual/en/function.pack.php

« previous php.notes (#163314) next »