The following small series will bring you an example code about the string and multi-hexadecimal conversion functions in PHP. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at the conversion function.
/*** [Convert a string to (2, 8, and 16 hexadecimal) ASCII code] * @ param string $ str [string to be processed] * @ param boolean $ encode [convert string to ASCII | convert ASCII to string] * @ param string $ intType [2, 8, hexadecimal flag] * @ return string byte_str [processing result] * @ author alexander */function strtoascii ($ str, $ encode = true, $ intType = "2 ") {if ($ encode = true) {$ byte_array = str_split ($ str); foreach ($ byte_array as & $ value) {$ value = ord ($ value ); switch ($ intType) {case 16: $ valu E = sprintf ("% 02x", $ value); break; case 8: $ value = sprintf ("% 03o", $ value); break; default: $ value = sprintf ("% 08b", $ value); break ;}} unset ($ value); $ byte_str = implode ('', $ byte_array );} else {$ chunk_size = $ intType = 16? 2: ($ intType = 8? 3: 8); $ byte_array = chunk_split ($ str, $ chunk_size); $ byte_array = array_filter (explode ("\ r \ n", $ byte_array )); foreach ($ byte_array as & $ value) {$ fun_name = $ intType = 16? 'Hexdec ': ($ intType = 8? 'Octed': 'bindec '); $ value = $ fun_name ($ value); $ value = chr ($ value);} unset ($ value ); $ byte_str = implode ('', $ byte_array);} return $ byte_str ;}
Multi-base in PHP
PHP integer values can be expressed in decimal, hexadecimal, octal, or binary. optional symbols (-or +) can be added before ).
Binary: [+-]? 0b [01] +
Gossip: [+-]? 0 [1-7] +
Decimal: [+-]? [1-9] [0-9] * | 0
Hexadecimal: [+-]? [XX] [0-9a-fA-F] +
Multi-hexadecimal conversion functions:
The above is all the sample code for the string and multi-hexadecimal conversion functions in PHP provided by the editor. I hope you can support PHP ~