Converting all non english characters to english ones.

Discussion in 'PHP' started by baris22, Dec 29, 2008.

  1. #1
    
    
    function conv($var){
    $chars = array(
    "À" => "A",
    "Â" => "A",
    "Ä" => "A",
    "Æ" => "AE",
    "È" => "E",
    "Ê" => "E",
    "Ì" => "I",
    "ÃŽ" => "I",
    "Ð" => "D",
    "Ã’" => "O",
    "Ô" => "O",
    "Ö" => "O",
    "Ø" => "O",
    "Ú" => "U",
    "Ü" => "U",
    "à" => "a",
    "â" => "a",
    "ä" => "a",
    "æ" => "ae",
    "è" => "e",
    "ê" => "e",
    "ì" => "i",
    "î" => "i",
    "ð" => "o",
    "ò" => "o",
    "ô" => "o",
    "ö" => "o",
    "ø" => "o",
    "ú" => "u",
    "ü" => "u",
    "Á" => "A",
    "Ã" => "A",
    "Ã…" => "A",
    "Ç" => "C",
    "É" => "E",
    "Ë" => "E",
    "Í" => "I",
    "Ï" => "I",
    "Ñ" => "N",
    "Ó" => "O",
    "Õ" => "O",
    "Ù" => "U",
    "Û" => "U",
    "Ý" => "Y",
    "ß" => "B",
    "á" => "a",
    "ã" => "a",
    "Ã¥" => "a",
    "ç" => "c",
    "é" => "e",
    "ë" => "e",
    "í" => "i",
    "ï" => "i",
    "ñ" => "n",
    "ó" => "o",
    "õ" => "o",
    "ù" => "u",
    "û" => "u",
    "ý" => "y",
    "ÿ" => "y");
    
      return str_replace(array_keys($chars),$chars,$var);
    }
    
    
    PHP:
    Hello,

    I am trying to convert all non english characters to english. Is there an easy way to do this? Has anybody already done this?

    Any suggestions wellcome.

    thanks
     
    baris22, Dec 29, 2008 IP
  2. clades

    clades Peon

    Messages:
    579
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Lol, those characters aren't english, they're a collection of Latin letters and Arabic digits.
    There's no such thing as english characters.
     
    clades, Dec 29, 2008 IP
  3. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #3
    @Clades: Wow, you bothered typing all that just to insult the original posters ignorance? Pretty lame.

    @OP:
    Here's a solution that'll work assuming you have iconv:
    echo iconv('', 'ASCII//TRANSLIT', $text);
    PHP:
    Please note, you may need to strip out some "extra" `^" and similar due to the way it works.

    Dan
     
    Danltn, Dec 29, 2008 IP
  4. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #4
    wawww thank you. i never thought about this.
     
    baris22, Dec 29, 2008 IP
  5. clades

    clades Peon

    Messages:
    579
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Lol you called baris ignorant, i didnt :D
     
    clades, Dec 30, 2008 IP