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 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程