Spanish Character Translation
Like this blog? Consider exploring one of our sponsored banner ads...
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); }
About this entry
You’re currently reading “Spanish Character Translation,” an entry on BRADINO
- Published:
- 12.17.08 / 6pm
- Category:
- PHP
- Tags:
1 Comment
Jump to comment form | comments rss [?]