Reputation: 1154
I'm building a website in Code Igniter and i'm trying to save products in a database. I don't know what kind of products i get. It's a XML file. There ara some times special characters in it so Code Igniter crashes. I fixed it like this
$search = array('â', 'à', 'á', 'ã', 'ä', 'å', 'Â', '€', 'š', '¢', 'Ã');
str_replace($search, '', $string)
But this is not nice and i haven't coverd all the possible special characters. My question is: is there a eassier way to get this done?
Upvotes: 0
Views: 1848
Reputation: 368
I believe you should take look at convert_accented_characters() function of Text Helper in CI
It transliterates high ASCII characters to low ASCII equivalents, useful when non-English characters need to be used where only standard ASCII characters are safely used, for instance, in URLs.
$string = convert_accented_characters($string); This function uses a companion config file application/config/foreign_chars.php to define the to and from array for transliteration.
Upvotes: 1
Reputation: 371
Sorry for the short answer but I think you have issues regarding handling UTF8 encoded characters and need to read this (a guide to working with PHP, MySQL and UTF8 character encoding - other guides are available ) -
http://www.toptal.com/php/a-utf-8-primer-for-php-and-mysql
Upvotes: 1