Conversion functions
/** * [string converted to (2,8,16) ASCII code] * @param string $str [Pending String] * @param boolean $encode [string converted to ascii| ASCII converted to string] * @param string $intType [2,8,16] * @return string byte_str [processing result] * @author Alexander */function Strtoas CII ($str, $encode =true, $intType = "2") {if ($encode = = True) {$byte _array = Str_split ($STR); foreach ($byte _array as & $value) {$value = ord ($value); Switch ($intType) {case: $value = 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 = = = 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? ' Octdec ': ' Bindec '); $value = $fun _name ($value); $value = Chr ($value); } unset ($value); $byte _str = Implode (", $byte _array); } return $byte _str;}
Multi-binary in PHP
PHP integer values can be expressed in decimal, hexadecimal, octal, or binary notation, preceded by an optional symbol (-or +).
Binary: [+-]?0b[01]+
Octal: [+-]?0[1-7]+
Decimal: [+-]? [1-9] [0-9]*|0
Hex: [+-]? [XX] [0-9a-fa-f]+
The multi-input conversion function:
The above is a small series for everyone to bring about the string in PHP and the multi-conversion function instance code all content, I hope that you support topic.alibabacloud.com~