Dave's Brain

Browse - Programming Tips - How can I remove accents from a string in php?

Date: 2017sep30
Language: php

Q.  How can I remove accents from a string in php?

A.  Use iconv() like this:

function removeAccents($s) { setlocale(LC_ALL, 'en_US.UTF8'); // Might have side-effects return iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $s); }
This will change bière -> biere The setlocale() changes the global locale for your entire program so that might cause side-effects but without it, if you are in the C locale, the accented letters will become question marks.

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.