Related questions:
- How to replace characters in a java String?
- How to replace special characters with their equivalent (such as " á " for " a") in C#?
As in the questions above, I’m looking for a reliable, robust way to reduce any unicode character to near-equivalent ASCII using PHP. I really want to avoid rolling my own look up table.
For example (stolen from 1st referenced question): Gračišće becomes Gracisce
The iconv module can do this, more specifically, the iconv() function:
The main hassle with iconv is that you just have to watch your encodings, but it’s definitely the right tool for the job (I used ‘Windows-1252’ for the example due to limitations of the text editor I was working with 😉 The feature of iconv that you definitely want to use is the
//TRANSLITflag, which tells iconv to transliterate any characters that don’t have an ASCII match into the closest approximation.