Hello,
I have a database with unicode encoding. Now I have a php script that read files and insert it to the db. But I have encoding problem and the results is gibrish.
How can I convert the text from the file to unicode? I've tried something like this: $preview_text = mb_internal_encoding("UTF-8"); But it doesn't work.
Any ideas?
Show us the gibberish
try html_entities() or html_special_chars()
I take it you want to convert é to é, so you don't get a square or <?> icon.
thanks for your answer. This is what I get for a very long file: ÿþ1 or ��1
So I guess it is more than a problem with special chars this is a very strange, PM me if you want me to send you the file
Use utf8_encode() and utf8_decode()
EDIT: Just noticed that that only works when the string you enter is iso-8859-1, if you're input string isn't iso have a look at iconv()
Make sure you are "talking" to the database in UTF8 before you run your select queries.
mysql_query("SET NAMES 'utf8'"); mysql_query("SET CHARACTER SET utf8");
If you need to manipulate the retrieved text in any way before you output it, you'll need to use the [man]mbstring[/man] extension to deal with it.
If outputting UTF8, make sure your content-type encoding is set. If you do this, do not use [man]htmlentities/man, but instead only use [man]htmlspecialchars/man.
<?php // before any output is sent: header('Content-Type: text/html;charset=utf-8'); // get text from DB, then: echo htmlspecialchars($text);