? Php/*** convert ASCII to hexadecimal and hexadecimal to ASCII * non-profit organizations or individuals may feel free to reprint them, for commercial purposes, please obtain the author's consent ** // Convert ASCII to hexadecimal functionasc2hex ($ str) {return '\ X '. substr (chunk_split (bin2hex ($ str), 2,
- /**
- *
- * Convert ASCII to hexadecimal and hexadecimal to ASCII
- * For non-profit organizations or individuals, please feel free to repost them. For commercial purposes, please obtain the author's consent.
- *
- */
- // Convert ASCII to hexadecimal
- Function asc2hex ($ str ){
- Return '\ X'. substr (chunk_split (bin2hex ($ str), 2,' \ X'), 0,-2 );
- }
- // Convert hexadecimal to ASCII
- Function hex2asc ($ str ){
- $ Str = join ('', explode ('\ X', $ str ));
- $ Len = strlen ($ str );
- For ($ I = 0; $ I <$ len; $ I + = 2) $ data. = chr (hexdec (substr ($ str, $ I, 2 )));
- Return $ data;
- }
- $ Asc = "haha ";
- $ Hex = asc2hex ($ asc );
- $ Asc = hex2asc ($ hex );
- Echo "hex:". $ hex;
- Echo"
- ";
- Echo "asc:". $ asc;
- ?>