note 105878 deleted from ref.strings by danbrown

From: Date: Thu, 22 Sep 2011 15:20:19 +0000
Subject: note 105878 deleted from ref.strings by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183346@lists.php.net to get a copy of this message
Note Submitter: fmaz008 at gmail dot com ---- Someone posted a str2bin fonction, this is a simpler version, using more PHP internal functions. <?php /** * Returns an ASCII string containing * the binary representation of the input data . **/ function str2bin($str, $mode=0) { $out = false; for($a=0; $a < strlen($str); $a++) { $dec = ord(substr($str,$a,1)); $bin = decbin($dec); $bin = str_pad($bin, 8, "0", STR_PAD_LEFT); /* Default-mode */ if ( $mode == 0 ) $out .= $bin; /* Human-mode (easy to read) */ if ( $mode == 1 ) $out .= $bin . " "; /* Array-mode (easy to use) */ if ( $mode == 2 ) $out[$a] = $bin; } return $out; } ?>

« previous php.notes (#183346) next »