ananaz Posted December 24, 2010 Share Posted December 24, 2010 Hello, I have this problem that when i fill my form (that i did in html) with for example "räv" (swedish for fox) somewhere the "ä" becomes non-readable, it might be in the mysql aswell. please help me come around this problem. This is where the data goes: Form>form.php>mysql>website.php Link to comment https://forums.phpfreaks.com/topic/222545-%C3%A4-%C3%A5-%C3%B6-and-other-unicode-in-php/ Share on other sites More sharing options...
johnny86 Posted December 24, 2010 Share Posted December 24, 2010 This is quote of my old reply in another topic: Charset issues are always a bit hard. But the best thing you can do to make sure your text is showing up correctly is to use the same charset allover your program. This means: - Save all your HTML, PHP, XML, CSS files etc in UTF-8 format (if utf-8 is the desired charset) - Make sure you have default charset in PHP / Apache / MySQL set to UTF-8 - Send appropriate headers always and keep meta info in your source about charset UTF-8 Make sure all data you get is in UTF-8 format. This is the most trickiest part for me. There is no way of knowing that a client will send you UTF-8 data even if you have done all correctly on your side. There will always be missbehaving browsers/clients that simply wants to harm you or doesn't work according to standards. There isn't much to do about that either. Since it's almost impossible to identify the charset of an incoming data. Except for just testing one by one. You could check PHPs iconv functions for some help. There are some user made functions in the comments too that can identify UTF-8 formatted string for example. All in all those doesn't get you too far. Best thing to do is make sure you use overall same charset in everything in your project. With iconv you could change all of the contents to UTF-8. And utf8_encode() & utf8_decode() functions will encode ISO-8859-1 to UTF-8 and other way around. Try using those functions on some strings that you know are ISO-8859-1 or UTF-8. You always need to know which charset the string is in order to convert it to another charset. Also: http://fi.php.net/manual/en/book.iconv.php Hope this helps. And I'd like to hear other opinions too. Because charset issues are annoying. Ecspecially if I don't know what charset the data I'm receiving is encoded. And the great thing in making sure you have all data encoded in UTF-8 is that whenever you print data to your page. htmlspecialchars() is enough sanitizing. So all you need to do afther that is just run all your "untrusted" data through that function if you know you have utf8 all over. =) Offcourse you might want to sanitize something else too. But that will be enough to not braking your site or anything. Link to comment https://forums.phpfreaks.com/topic/222545-%C3%A4-%C3%A5-%C3%B6-and-other-unicode-in-php/#findComment-1150978 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.