This article mainly introduces php's methods for converting binary data and text data. The example analyzes the skills related to text and number conversion, which has some reference value, for more information about how to convert binary and text in php, see the following example. 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.