今天在做的事情是将一个as3项目的部分代码移植到PHP中来,记录下移植过程中遇到的两个问题。

1AS3String类的charCodeAt函数是返回字符的unicode编码,而在PHP中并没有直接与之对应的库函数,可以用下面这个函数做替代:

<?php
function uniord($str,$from_encoding=false){
        
$from_encoding=$from_encoding ? $from_encoding : 'UTF-8';

        
if(strlen($str)==1
                
return ord($str);
                
        
$str=mb_convert_encoding($str, 'UCS-4BE', $from_encoding);
        
$tmp=unpack('N',$str);
        
return $tmp[1];
}
$str="12345";
$result=array();
for($i=0,$l=mb_strlen($str,'utf-8');$i<$l;++$i){
        
$result[]=uniord(mb_substr($str,$i,1,'utf-8'));
}
echo join(",",$result);
?>

相关文章:

  • 2021-09-20
  • 2022-02-14
  • 2021-11-12
  • 2021-07-21
  • 2021-08-25
  • 2022-01-12
  • 2021-09-05
  • 2021-06-16
猜你喜欢
  • 2021-04-25
  • 2021-09-02
  • 2022-03-04
  • 2021-09-16
  • 2021-05-22
  • 2022-02-03
  • 2021-09-19
相关资源
相似解决方案