php iconv translit for removing accents: not working as excepted?

后端 未结 7 1231
终归单人心
终归单人心 2020-12-10 06:09

consider this simple code:

echo iconv(\'UTF-8\', \'ASCII//TRANSLIT\', \'è\');

it prints

 `e

instead of ju

7条回答
  •  有刺的猬
    2020-12-10 06:45

    I'm tempted to say "nothing", although this is a little outside my expertise. PHP's iconv() is notorious, and the inspiration for many workarounds, including

    • dropping to the system's iconv utility (Unix & Linux)
    • crafting a lookup table
    • replacing all accented characters with an ASCII equivalent as kind of a preprocessing stage
    • setting LC_COLLATE (which doesn't seem to work for everyone)
    • use htmlentities() instead of iconv()

    Read the comments for iconv() documentation for more inspiration. (Or commiseration. Too close to call.)

提交回复
热议问题