可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):

问题:

consider this simple code: echo iconv('UTF-8', 'ASCII//TRANSLIT', 'è');

it prints `e

instead of just e

do you know what I am doing wrong?

nothing changed after adding setlocale setlocale(LC_COLLATE, 'en_US.utf8'); echo iconv('UTF-8', 'ASCII//TRANSLIT', 'è');

回答1:

I have this standard function to return valid url strings without the invalid url characters. The magic seems to be in the line after the //remove unwanted characters comment.

This is taken from the Symfony framework documentation: http://www.symfony-project.org/jobeet/1_4/Doctrine/en/08 which in turn is taken from http://php.vrana.cz/vytvoreni-pratelskeho-url.php but i don't speak Czech ;-) function slugify($text) { // replace non letter or digits by - $text = preg_replace('#[^\\pL\d]+#u', '-', $text); // trim $text = trim($text, '-'); // transliterate if (function_exists('iconv')) { $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); } // lowercase $text = strtolower($text); // remove unwanted characters $text = preg_replace('#[^-\w]+#', '', $text); if (empty($text)) { return 'n-a'; } return $text; } echo slugify('é'); // --> "e"

回答2:

cf @tchrist, with INTL php extension preg_replace('/\pM*/u','',normalizer_normalize( $mystring, Normalizer::FORM_D));

becomes

As tchrist emphasises, not all unicode characters are considered decomposable:

extract from Unicode charts:

U0080.pdf ≡ 0049 I 0308 ¨

no decomposition available, IMHO strangely (we could consider ASCII letter D as an acceptable equivalent).

U0100.pdf

even stranger: this one is identified as LATIN CAPITAL LETTER D (with stroke), but not decomposable as such! Perhaps a cooler solution should be to get the unicode description of each char, and compare it with the description of each ascii char (and replace accordingly). Anyone? ;-]

回答3:

When doing transliteration, you have to make sure that your LC_COLLATE is properly set, otherwise the default POSIX will be used.

回答4:

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.)

回答5:

It seems the standard way to handle this is with a "removing accents" function which you can find in library's like flourish or CMS's like Wordpress. Iconv seems to be unable to translate accents (and rightly so) since this isn't a good idea for anything other than URL slugs.

回答6:

It happen with me with pure iconv without php. The Trick was to set LANG environment value to en_US.UTF-8 (it was hu_HU.UTF-8 before, in my case). After it worked as expected.

回答7:

It seem that it depend of the php version...

TestCase #1 php -version

PHP 7.0.0RC8 (cli) (built: Nov 25 2015 12:36:50) ( NTS ) Copyright (c) 1997-2015 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies php -r "var_dump(iconv('UTF-8', 'ASCII//TRANSLIT', 'è'));" string(2) "`e"

TestCase #2 php -version

PHP 7.0.8-1~dotdeb+8.1 (cli) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.8-1~dotdeb+8.1, Copyright (c) 1999-2016, by Zend Technologies php -r "var_dump(iconv('UTF-8', 'ASCII//TRANSLIT', 'è'));" string(1) "e"

php iconv translit,php iconv translit for removing accents: not working as excepted?相关推荐

  1. php iconv gbk,php iconv中文乱码怎么办

    php iconv中文乱码的解决办法:首先下载libiconv函数库,并安装libiconv:然后重新编译php:最后在需要转成的编码后加入参数"//IGNORE"即可. php中 ...

  2. iconv java_libiconv之iconv函数的使用方法

    iconv函数原型为: size_t iconv (iconv_t cd,  char* * inbuf, size_t *inbytesleft, char* * outbuf, size_t *o ...

  3. php中icon,php中iconv函数的使用方法

    本篇文章中的内容介绍的是php中iconv函数的使用方法,在这里分享给大家,有需要的朋友可以参考一下 最近在做一个程序,需要用到iconv函数把抓取来过的utf-8编码的页面转成gb2312, 发现只 ...

  4. PHP中的mb_convert_encoding与iconv函数介绍

    iconv函数库能够完成各种字符集间的转换,是php编程中不可缺少的基础函数库.  1.下载libiconv函数库http://ftp.gnu.org/pub/gnu/libiconv/libicon ...

  5. libiconv android,iconv库 android ndk可运行

    [实例简介] 是一个iconv库,能够在android上编译运行,生成SO库. [实例截图] [核心代码] cb24acd8-e96e-4981-89f0-8227dc4cc0c4 └── iconv ...

  6. php中iconv函数使用_字符集转换编码

    php中iconv函数介绍 iconv函数库能够完成各种字符集间的转换,是php编程中不可缺少的基础函数库. 1.下载libiconv函数库http://ftp.gnu.org/pub/gnu/lib ...

  7. iconv命令 php,PHP中iconv函数知识汇总

    iconv函数库能够完成各种字符集间的转换,是php编程中不可缺少的基础函数库.本文内容是参考了网上的其他资源,然后结合自己的实践,有需要的小伙伴可以参考下. 今天在修改论文在线的时候,遇到了icon ...

  8. php iconv_strlen,iconv详解

    头文件"inconv.h".iconv命令可以将一种已知的字符集文件转换成另一种已知的字符集文件. 它的作用是在多种国际编码格式之间进行文本内码的转换. 作为编程接口的iconv包 ...

  9. php mysql iconv_php中iconv函数使用方法

    最近在做一个程序,需要用到iconv函数把抓取来过的utf-8编码的页面转成gb2312, 发现只有用iconv函数把抓取过来的数据一转码数据就会无缘无故的少一些. iconv函数库能够完成各种字符集 ...

  10. iconv 判断字符编码_iconv字符编码转换全攻略

    iconv(http://www.gnu.org/software/libiconv/)是一个开源的字符编码转换库,可以"方便"的完成几乎所有的编码转换工作.说简单是因为,它常用的 ...

最新文章

  1. 性能测试中传——lr理论基础(四)
  2. 如何在您的笔记本上搭建View 演示环境 -5.配置View Connection Server
  3. [R语言画图]气泡图symbols
  4. 经营成功的测试职业生涯
  5. WS-Eventing、WS-Transfer Web服务标准
  6. 学习OpenCV,看这些!
  7. android 彩蛋 miui,MIUI12最新更新,安卓11彩蛋终于出现,流畅度提升
  8. 全文索引 - Pomelo.EFCore.MySql
  9. 价值98元的千神资源网模板
  10. Nginx配置性能优化的方法
  11. SCI/SSCI期刊列表已更新,这几本期刊被剔除~
  12. redis在php下面的命令大全
  13. HTML文件命名规范大全
  14. 复杂网络中小世界网络的MATLAB实现
  15. java怎么编写木马_Java也能写木马~(附源码!)
  16. 【密码学RSA】rsa_p高位泄露(2021四川省数字创新赛题)
  17. Qt5 模拟鼠标点击
  18. Controllable Generation from Pre-trained Language Models via Inverse Prompting翻译
  19. Maximum Absurdity
  20. 小Hi和小Ho的礼物

热门文章

  1. 计算机信息管理的检索步骤,信息检索策略与步骤
  2. MacBook连接打印机-惠普HP LaserJet Pro MFP M427fdn 连接方法
  3. C++拷贝构造函数专题
  4. 代收邮件服务器(pop,接收邮件服务器(POP)是?什么是 POP3? POP3 命令包括什么?
  5. python设置主题背景
  6. oracle cude报错,转载oracle rollup和cube函数使用心得
  7. IPV6 DNS服务器地址列表
  8. Java中除法运算符简介说明
  9. HTML 制作钓鱼网站实现跳转(简篇)
  10. 有限元基础及ANSYS应用 - 第9节 - 1 平面应力问题的ANSYS分析