Codes, Thoughts and Experiences

How to convert foreign chars on Code Igniter

Working with foreign chars on Code Igniter is super simple. I’ve been working on website with vietnamese language for quite some time. Yes, vietnamese character with their curly accessories on alphabets.

For example if you use slug on your vietnamese language on url you will get “Disallowed Character” error. Another case if you are working with payment gateway, unfortunately they don’t accept charset except UTF-8, eg : The famous PayPal and others.

Enough talks, here i show you how.

First, load the Text Helper, or you can put it on autoload config.

$this->load->helper('text');

After the helper is loaded then here is how you use it. Simply just call this method to convert it.

$string = convert_accented_characters($string);

You can add the character mapping on foreign_chars.php under config directory. Here is the example.

Yes. It is done. Hope this helps. This post is more like bookmark so i know where to look when i need it 😛