Posted By

KuhlMensch on 03/02/12


Tagged

characters encoding iconv accented


Versions (?)

iconv: Force encoding before removing accented characters


 / Published in: PHP
 

I was trying to remove accented characters and the character substitution was incorrect. After mucking around I realised I needed to encode.

I don't know exactly why I needed to force encoding. It might simply be because the server was linux.

  1. $GLOBALS['normalizeChars'] = array(
  2. 'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', '�'=>'A', '�'=>'A', '�'=>'A', '�'=>'A', '�'=>'A', '�'=>'A', '�'=>'A', '�'=>'C', '�'=>'E', '�'=>'E',
  3. '�'=>'E', '�'=>'E', '�'=>'I', '�'=>'I', '�'=>'I', '�'=>'I', '�'=>'N', '�'=>'O', '�'=>'O', '�'=>'O', '�'=>'O', '�'=>'O', '�'=>'O', '�'=>'U',
  4. '�'=>'U', '�'=>'U', '�'=>'U', '�'=>'Y', '�'=>'B', '�'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c',
  5. 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o',
  6. 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y'
  7. );
  8.  
  9. function cleanForShortURL($toClean) {
  10. $toClean = iconv('UTF-8', 'ISO-8859-1//TRANSLIT//IGNORE', $toClean );
  11. return strtr($toClean, $GLOBALS['normalizeChars']);
  12.  
  13. }

Report this snippet  

You need to login to post a comment.