Mutual Conversion between PHP binary and string. Mutual Conversion between PHP binary and string [code] php code :? Phpheader (Content-type: texthtml; charsetutf-8); *** converts a string to a binary string * @ paramtype $ str * @ r PHP: mutual conversion between the binary string
[Code] php code:
Header ("Content-type: text/html; charset = utf-8 ");
/**
* Convert a string to a binary string.
* @ Param type $ str
* @ Return type
*/
Function StrToBin ($ str ){
// 1. list each character
$ Arr = preg_split ('/(?
// 2. unpack characters
Foreach ($ arr as & $ v ){
$ Temp = unpack ('H * ', $ v); $ v = base_convert ($ temp [1], 16, 2 );
Unset ($ temp );
}
Return join ('', $ arr );
}
/**
* Converts binary data to a string.
* @ Param type $ str
* @ Return type
*/
Function BinToStr ($ str ){
$ Arr = explode ('', $ str );
Foreach ($ arr as & $ v ){
$ V = pack ("H". strlen (base_convert ($ v, 2, 16), base_convert ($ v, 2, 16 ));
}
Return join ('', $ arr );
}
Echo StrToBin ("php secondary development: www. php2.cc ");;
Echo'
';
Echo BinToStr ("1110000 1101000 1110000 111001001011101010001100 111001101010110010100001 111001011011110010000000 111001011000111110010001 111011111011110010011010 1110111 1110111 1110111 101110 1110000 1101000 1110000 110010 101110 1100011 1100011 ");
Pipeline [code] php code :? Php header (Content-type: text/html; charset = utf-8);/*** converts a string to a binary string * @ param type $ str * @ r...