I have a page with a form where users write a code in swedish with åäö and ÅÄÖ. It’s UTF-8 on the page and in the db as well. But I need to store the text as it is.
When it’s stored in the table it looks like this: ÅÄÖ åäö
I just want it to be åäö ÅÄÖ and not like the above and not like this & auml ;
What do I need to convert it to the correct chars?
I think I have tried almost everything I can come up with, but with no luck.
The MySQL table is also set to UTF-8
How are you viewing the tables values, from the command line? eg.
mysql> SELECT `countries`.`name` AS `country_name`,
-> `states`.`name` AS `state_name`,
-> `cities`.`name` AS `city_name`
-> FROM `countries`
-> INNER JOIN `states` ON `countries`.`id` = `states`.`country_id`
-> INNER JOIN `cities` ON `states`.`name` = `cities`.`state_name`
-> WHERE `countries`.`id` = 5 ORDER BY `cities`.`name`;
+--------------+-------------------+-------------+
| country_name | state_name | city_name |
+--------------+-------------------+-------------+
| Sweden | Västra Götaland | Gothenburg |
| Sweden | Skåne | Helsingborg |
| Sweden | Stockholm | Huddinge |
| Sweden | Jönköping | Jönköping |
| Sweden | Östergötland | Linköping |
| Sweden | Skåne | Malmo |
| Sweden | Örebro | Örebro |
| Sweden | Stockholm | Stockholm |
| Sweden | Uppsala | Uppsala |
| Sweden | Västmanland | Västerås |
+--------------+-------------------+-------------+
10 rows in set (0.07 sec)
The output is then used in a mobile app which is already ready and coded.
When I write the text in the db fields in phpmyadmin as it’s supposed to looks correct in the app.
But when I insert it from my page it puts the wrong chars in the table.
That’s why I need to insert it as it is.
This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.
Try to make sure everything is utf-8. Your scripts charset, the file save format, the table collation and, the bit that caught me out recently, the connection to the database.
I had everything but the connection set utf-8, and when I pulled a pound sign from a table and displayed it, it showed as a “mystery symbol”. Once I set the connection to utf-8, everything was fine.
actually, you don’t want any of the escaping function as their purpose is to escape data for HTML output (and when using UTF-8, only htmlspecialchars() is necessary).
have you set the DB connection to UTF-8? (that is NOT the same as defining the character set in the DB!)