将编码字符转换为普通[A-Z]字符

时间:2012-10-22 20:34:14

标签: php xml encoding character-encoding

  

可能重复:
  How to transliterate accented characters into plain ASCII characters?

我在PHP中遇到编码问题,例如我想要

要在Orléans

中转换

Orleans

AngoulêmeAngouleme

ŇN

......依此类推这里的表格

http://www.thesauruslex.com/typo/eng/enghtml.htm

有解决方案吗?并且当脚本遇到非[A-Z]字符以使其成为XML ENTITY时。

谢谢!

3 个答案:

答案 0 :(得分:0)

可能使用:iconv('utf-8', 'ascii//TRANSLIT', $text);

此处有更多信息:http://php.net/manual/en/function.iconv.php

答案 1 :(得分:0)

  $str1 = 'Orléans'
  $str2 = 'Angoulême'
  $rule = 'NFD; [:Nonspacing Mark:] Remove; NFC';

  $transliter = Transliterator::create($rule); 
  echo $transliter->transliterate($str1);
  echo $transliter->transliterate($str2);

答案 2 :(得分:-2)

$unwanted_array = array('Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U',
'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U','Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c',
'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o',
'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u','ü'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y' );


// TESTING
$str1 = 'Orléans';
$str2 = 'Angoulême';
echo strtr($str1,$unwanted_array);

这就是我所需要的,为什么工作得这么好,又如此简单?