This article mainly introduces the PHP binary and the conversion between the strings of teaching, the need for friends can come to understand.
The PHP code is as follows:
<?php header ("content-type:text/html; Charset=utf-8 "); /** * Converts a string into binary * @param type $STR * @return Type */function Strtobin ($str) {//1. list each character $arr = Preg_split ('/(? <!^) (?! $)/U ', $str); 2.unpack character foreach ($arr as & $v) {$temp = unpack (' h* ', $v); $v = Base_convert ($temp [1], 2); unset ($temp);} retur N Join ("', $arr); }/** * Binary converted to String * @param type $STR * @return Type */function Bintostr ($str) {$arr = Explode (", $str); foreach ($arr A S & $v) {$v = Pack ("H". Strlen (Base_convert ($v, 2, +)), Base_convert ($v, 2, +));} return join (', $arr); } Echo Strtobin ("PHP two times Development: www.php2.cc");; Echo ' <br/> '; Echo bintostr ("1110000 1101000 1110000 111001001011101010001100 111001101010110010100001 111001011011110010000000 111001011000111110010001 111011111011110010011010 1110111 1110111 1110111 101110 1110000 1101000 1110000 110010 101110 11 00011 1100011 ");
I hope this article will help you, and PHP binary and string conversion between the content is to introduce you here. I hope you will continue to follow our website! Want to learn PHP can continue to focus on this site.