熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> PHP編程 >> 正文

淺析PHP的ASCII碼轉換類

2022-06-13   來源: PHP編程 
本篇文章是對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;
}


From:http://tw.wingwit.com/Article/program/PHP/201311/20893.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.