dongqun1656 2011-04-14 20:53
浏览 119
已采纳

获取iconv转换我的字符串

I have the following string:

ᴰᴶ Bagi

Is it possible to let iconv make it into DJ Bagi?

First I tried with:

$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);

Which resulted in the following notice:

Notice: iconv() [function.iconv]: Detected an illegal character in input string 

On the PHP site I saw someone using:

//IGNORE//TRANSLIT

While this prevents the notice I only get:

Bagi

  • 写回答

1条回答 默认 最新

  • dongqi6964 2011-04-14 21:53
    关注

    I initially thought that this is an encoding problem on your end, but if I copy + paste those characters locally from the soundcloud source page:

    ᴰᴶ Bagi
    

    and try to iconv them, I get the same result as you do. That means that the data is UTF-8, but iconv does not recognize as a "child" of D. Unable to convert the character, it complains (a bit misleadingly IMO) about an illegal character.

    Edit: This seems indeed true. Superscript D is not in the Unicode Superscripts and Subscripts range, but it's a phonetic character. That's probably why they can't be mapped back to their "parent" letter. Here is more info on

    As far as I can see, your only choice is to replace the characters manually.

    The most primitive example of a replace is

    str_replace("ᴰ", "D", $string);
    

    (note that your source file needs to be stored as UTF-8 for this to work)

    For an elegant solution, you could build an array out of the source and replacement characters, and pass that to the str_replace call.

    Or call DJ Bagi and tell him to get the damn letters straight. You will notice that Soundcloud's URL builder encountered exactly the same problem.

    soundcloud.com/bagi 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?