Convert encoded characters into normal [A-Z] chara

2019-09-22 00:17发布

Possible Duplicate:
How to transliterate accented characters into plain ASCII characters?

I have a problem with encoding in PHP, for example i want

Orléans to be transformed in Orleans

Angoulême to Angouleme

Ň to N

... and so on see the table here

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

Is there a solution to this? And also when the script encounter a non [A-Z] character to make it XML ENTITY.

Thank you!

3条回答
Rolldiameter
2楼-- · 2019-09-22 00:23
  $str1 = 'Orléans'
  $str2 = 'Angoulême'
  $rule = 'NFD; [:Nonspacing Mark:] Remove; NFC';

  $transliter = Transliterator::create($rule); 
  echo $transliter->transliterate($str1);
  echo $transliter->transliterate($str2);
查看更多
放我归山
3楼-- · 2019-09-22 00:42
$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);

This is what i needed, why is working so well, yet is so simple ?

查看更多
Deceive 欺骗
4楼-- · 2019-09-22 00:45

Possibly use: iconv('utf-8', 'ascii//TRANSLIT', $text);

More info here: http://php.net/manual/en/function.iconv.php

查看更多
登录 后发表回答