Php implements mutual conversion between binary and text,
This example describes how php converts binary data and text data. Share it with you for your reference. The details are as follows:
This Code contains two functions: bin2text, binary to text, text2bin, and text to binary.
<? Phpfunction bin2text ($ bin_str) {$ text_str = ''; $ chars = explode (" \ n ", chunk_split (str_replace (" \ n ",'', $ bin_str ), 8); $ _ I = count ($ chars); for ($ I = 0; $ I <$ _ I; $ text_str. = chr (bindec ($ chars [$ I]), $ I); return $ text_str;} function text2bin ($ txt_str) {$ len = strlen ($ txt_str ); $ bin = ''; for ($ I = 0; $ I <$ len; $ I) {$ bin. = strlen (decbin (ord ($ txt_str [$ I]) <8? Str_pad (decbin (ord ($ txt_str [$ I]), 8, 0, STR_PAD_LEFT): decbin (ord ($ txt_str [$ I]);} return $ bin ;} print text2bin ('How are you gentlements? ');?>
I hope this article will help you with php programming.