php实现javascipt charCodeAt/fromCharCode方法

  php实现javascipt charCodeAt方法

function charCodeAt($str, $index)
{
    $char = mb_substr($str, $index, 1, 'UTF-8'); 
    if (mb_check_encoding($char, 'UTF-8'))
    {
        $ret = mb_convert_encoding($char, 'UTF-32BE', 'UTF-8');
        return hexdec(bin2hex($ret));
    }
    else
    {
        return null;
    }
}

  php实现javascipt fromCodeAt方法

    function fromCharCode($codes) {
      if (is_scalar($codes)) $codes= func_get_args();
      $str= '';
      foreach ($codes as $code) $str.= chr($code);
      return $str;
    }

 

加支付宝好友偷能量挖...


原创文章,转载请注明出处:php实现javascipt charCodeAt/fromCharCode方法

评论(0)Web开发网
阅读(337)喜欢(0)PHP/apache/Perl