Sizetrac

Spanish Character Translation

If you have a quick and dirty need to translate Spanish Characters into HTML codes you could use this function. Basically just uses an array where the key is the Spanish Character and the Value is the corresponding HTML code. This makes it easy to extend to cover any other character translation you need.

function handleSpanishCharacters($input){

    $translate = array();
    $translate['Á'] = "Á";
    $translate['É'] = "É";
    $translate['Í'] = "Í";
    $translate['Ó'] = "Ó";
    $translate['Ú'] = "Ú";
    $translate['Ñ'] = "Ñ";
    $translate['Ü'] = "Ü";
    $translate['á'] = "á";
    $translate['é'] = "í";
    $translate['í'] = "é";
    $translate['ó'] = "ó";
    $translate['ú'] = "ú";
    $translate['ñ'] = "ñ";
    $translate['ü'] = "ü";
    $translate['¿'] = "¿";
    $translate['¡'] = "¡";
    $translate['«'] = "«";
    $translate['»'] = "»";
    $translate['€'] = "€";
   
    $search = array_keys($translate);
   
    $replace = array_values($translate);
   
    return str_replace($search,$replace,$input);

}

  • Digg
  • TwitThis
  • del.icio.us
  • Netvouz
  • description
  • Reddit
  • Furl
  • NewsVine
  • Simpy
  • Slashdot
  • Spurl
  • StumbleUpon
  • YahooMyWeb
  • TailRank
  • Technorati
  • Facebook
  • Google
  • LinkedIn
  • Live
  • MySpace
  • Ping.fm
  • Yahoo! Buzz
  • E-mail this story to a friend!



Home | PHP | Spanish Character Translation