<?php
    
       $prenamename="wo中国";
       $temp = mb_convert_encoding($prenamename,"HTML-ENTITIES","gb2312");
       echo "temp=".$temp;
?>//右键查看源文件得到的结果是temp=wo&#20013;&#22269;//"中国"的编码==&#20013;&#22269;
需要问的问题:就是为什么英文字符wo不转换编码呢。
我也希望"wo"字符跟"中国"字符产生类似的编码==&#0000这样的结果

解决方案 »

  1.   

    大家看一下我用java实现和php实现的方式
    要是输出中文俩个语言的结果是一样的。要是英文或者数字。php得不到结果。
    我把代码发出来
    ---------------------------------------------
    java实现方式public class d {
    public static void main(String args[]){
    //结果 4e2d56fd
    System.out.println(fileNameHex("中国"));
    //结果 003500320030
    System.out.println(fileNameHex("520"));



    }
     

     private static String fileNameHex(String fileName) {
     StringBuffer sb = new StringBuffer();
     for (int i = 0; i < fileName.length(); i++) {
     
     String temp = Integer.toHexString(fileName.charAt(i));
     
     if(temp.length() == 2 ) {
     sb.append("00"+temp);
     }else{
     sb.append(temp);
     }
    }
     return sb.toString();
     }
     
     
     }
    -------------------------------------------------------
    -------------------------------------------------------
    php实现方式<?php
     function toStrHex($unicodestr){
    $explodeUnicodestr=explode("&#",$unicodestr);
      for ($i = 1; $i < count($explodeUnicodestr); $i++) {
           $leng=strpos($explodeUnicodestr[$i],";");
         
          if ($leng>0){
         
            $temp=  substr($explodeUnicodestr[$i],0,$leng);
      
          }
          else {
       
           $temp=$explodeUnicodestr[$i];
          }
           
          if(strlen($temp)==2){
             $temp="00".$temp;
          }
          
           $temp = dechex($temp); 
            $strsb.=$temp;   
    }
      return $strsb;

    }
      //输出的结果:hexFilename=4e2d56fd ; 
     $hexFilename= toStrHex(mb_convert_encoding("中国","HTML-ENTITIES","gb2312")); 
     echo "hexFilename=".$hexFilename."<br>" ;
     $hexFilename2 = toStrHex(mb_convert_encoding("520","HTML-ENTITIES","gb2312"));
      //输出的结果:hexFilename2=; 
      echo "hexFilename2=".$hexFilename2."<br>" ;---------------------------------------------------------
    求助为什么php字符串是英文或者数字的时候。输出的结果为空呢。
    谢谢各位大侠的帮忙。希望帮我改一下程序。怎么才能得到和java一样的结果呢
      

  2.   

    mb_convert_encoding函数就是这么设定的,首先你要知道
    HTML-ENTITIES 是什么意思http://114.xixik.com/character/要想把ascii码也转成&#90;的样子得自己转换了,echo '&#',ord('a'),';';不过要注意数字本身也是ascii码,别搞了死循环
      

  3.   

    参考这里http://blog.csdn.net/yw1386/archive/2009/10/14/4671845.aspx
    希望对你有帮助