php

位置:IT落伍者 >> php >> 浏览文章

浅析PHP的ASCII码转换类


发布日期:2022年11月27日
 
浅析PHP的ASCII码转换类
本篇文章是对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;
}

               

上一篇:php定时计划任务的实现方法

下一篇:7款PHP环境搭建工具介绍