0

Possible Duplicate:
how to replace special characters with the ones they're based on in PHP?

I need to sanitize a string which will include special characters (foreign language keyboards, etc.) and I need to change them to say "ä => a" while not removing characters like "_", "-" and "/".

Community
  • 1
  • 1
qalny
  • 5
  • 3
  • 1
    How is your rule defined for removing `special characters`? There are literally hundreds of characters in Unicode that have various markings on them, not to mention non-latin-alphabet characters. How are those to be handled? If you do generate an exhaustive list, you may find the [`strtr`](http://us3.php.net/strtr) command useful for this purpose. – mellamokb Nov 10 '11 at 04:08
  • Have you tried to solve this yourself? Googling **[regex replace everything except](http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=regex+replace+everything+except)** produces quite a lot of results. – Blender Nov 10 '11 at 04:08
  • I'm doing something like '/(à|á|â|ã|ä|å|æ)/' => 'a'. Yes I have tried, wouldn't come here otherwise. @GabiPurcaru Not a duplicate, as you see I didn't ask only how to replace characters, but asked how to replace characters with leaving some out. – qalny Nov 10 '11 at 04:13
  • 1
    @qalny Since `_-/` aren't based on any other characters, they won't be replaced using any of the methods in the other question. – deceze Nov 10 '11 at 04:15

1 Answers1

5
print iconv('UTF-8', 'ASCII//TRANSLIT', 'à|á|â|ã|ä|å|æ');

a|a|a|a|a|a|ae

No need to regex. The right tool for the right job.

chx
  • 11,270
  • 7
  • 55
  • 129