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.
$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);
}
You’re currently reading “ Spanish Character Translation ,” an entry on BRADINO
- Published:
- 12.17.08 / 6pm
- Category:
- PHP























Hi,
In some communities in Spain uses the character “ç” and “Ç”.
The entity number translation is “Ç” and “ç” respectively.
For more info: http://www.w3schools.com/tags/ref_entities.asp
Your blog is great, congratulations.
Oops… wordpress converts the entity number… Ç” and “ç” respectively.