一行代码实现字符串的16进制编码解码

function hexEncode($s) {
    return preg_replace(‘/(.)/es’,”str_pad(dechex(ord(‘\1′)),2,’0’,STR_PAD_LEFT)”,$s);    
}
function hexDecode($s) {
    return preg_replace(‘/(w{2})/e’,”chr(hexdec(‘\1’))”,$s);
}
echo hexDecode(hexEncode(“北京n欢迎您!”));
?>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.