字符串转16进制
- public static function String2Hex($string){
- $hex = '';
- for ($i=0; $i<strlen($string); $i++){
- $ord = ord($string[$i]);
- $hexCode = dechex($ord);
- $hex .= substr('0'.$hexCode, -2);
- }
- return strToUpper($hex);
- }
复制代码
16进制转字符串
- public static function Hex2String($hex){
- $string='';
- for ($i=0; $i < strlen($hex)-1; $i+=2){
- $string .= chr(hexdec($hex[$i].$hex[$i+1]));
- }
- return $string;
- }
复制代码
|