本篇文章是对PHP的ASCII码转换类进行了详细的分析介绍
需要的朋友参考下
复制代码 代码如下:
class ascii
{
function decode($str)
{
preg_match_all( "/(d{})/" $str$a);
$a = $a[];
foreach ($a as $dec)
{
if ($dec < )
{
$utf = chr($dec);
}
else if ($dec < )
{
$utf = chr( + (($dec ($dec % )) / ));
$utf = chr( + ($dec % ));
}
else
{
$utf = chr( + (($dec ($dec % )) / ));
$utf = chr( + ((($dec % ) ($dec % )) / ));
$utf = chr( + ($dec % ));
}
}
return $utf;
}
function encode($c)
{
$len = strlen($c);
$a = ;
while ($a < $len)
{
$ud = ;
if (ord($c{$a}) >= && ord($c{$a})< =)
{
$ud = ord($c{$a});
$a += ;
}
else if (ord($c{$a}) >= && ord($c{$a})< =)
{
$ud = (ord($c{$a}))* + (ord($c{$a+}));
$a += ;
}
else if (ord($c{$a}) >= && ord($c{$a})< =)
{
$ud = (ord($c{$a}))* + (ord($c{$a+}))* + (ord($c{$a+}));
$a += ;
}
else if (ord($c{$a}) >= && ord($c{$a})< =)
{
$ud = (ord($c{$a}))* + (ord($c{$a+}))* + (ord($c{$a+}))* + (ord($c{$a+}));
$a += ;
}
else if (ord($c{$a}) >= && ord($c{$a})< =)
{
$ud = (ord($c{$a}))* + (ord($c{$a+}))* + (ord($c{$a+}))* + (ord($c{$a+}))* + (ord($c{$a+}));
$a += ;
}
else if (ord($c{$a}) >= && ord($c{$a})< =)
{
$ud = (ord($c{$a}))* + (ord($c{$a+}))* + (ord($c{$a+}))* + (ord($c{$a+}))* + (ord($c{$a+}))* + (ord($c{$a+}));
$a += ;
}
else if (ord($c{$a}) >= && ord($c{$a})< =)
{ //error
$ud = false;
}
$scill = "&#$ud;";
}
return $scill;
}