文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>php一般字符和16进制字符互相转换的函数

php一般字符和16进制字符互相转换的函数

时间:2007-02-17  来源:PHP爱好者

<?
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
function SingleDecToHex($dec)
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
{
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
$tmp="";
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
$dec=$dec%16;
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
if($dec<10)
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
return $tmp.$dec;
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
$arr=array("a","b","c","d","e","f");
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
return $tmp.$arr[$dec-10];
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
}
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
function SingleHexToDec($hex)
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
{
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
$v=Ord($hex);
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
if(47<$v&&$v<58)
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
return $v-48;
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
if(96<$v&&$v<103)
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
return $v-87;
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
}
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
function SetToHexString($str)
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
{
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
if(!$str)return false;
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
$tmp="";
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
for($i=0;$i<strlen($str);$i++)
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
{
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
$ord=Ord($str[$i]);
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
$tmp.=SingleDecToHex(($ord-$ord%16)/16);
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
$tmp.=SingleDecToHex($ord%16);
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
}
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
return $tmp;
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
}
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
function UnsetFromHexString($str)
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
{
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
if(!$str)return false;
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
$tmp="";
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
for($i=0;$i<strlen($str);$i+=2)
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
{
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
$tmp.=chr(SingleHexToDec(substr($str,$i,1))*16+SingleHexToDec(substr($str,$i+1,1)));
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
}
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
return $tmp;
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
}
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
?>
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
<html><body>
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
SetToHexString("大家好")=<?=SetToHexString("大家好")?><br>
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
UnsetFromHexString(SetToHexString("大家好"))=<?=UnsetFromHexString(SetToHexString("大家好"))?>
c hina it power . c omwC1GMpjsm9E64aCZjlY8QeAfz
</body></html>
非常全面的一个php技术网站,php 爱好者站 http://www.phpfans.net 有相当丰富的文章和源代码.
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载