Jump to content

fread with encoding type?


tapius1

Recommended Posts

I have a HUGE issues, im reading in a .txt file which contains foreign letters like, " ö " however, when i use fread,

 $fileOfRecords = fread($handle, filesize($filename));    

  and insert into the MSSQL Database, (The database is setup to handle encoding types with such character sets) When reviewing the text in the tables, such characters like ö turn into  "ö" making the text in the tables garbage.

 

My question is - how can i make sure that when I read these files and do my table inserts, that the correct character is being inserted. I know for a fact that the Database can handle these characters as Ive just done a replace of ö for ö, and ö stayed in the tables, so it is a matter of my php script.

 

Any help would  be greatly appreciated.

Thanks

Link to comment
https://forums.phpfreaks.com/topic/223423-fread-with-encoding-type/
Share on other sites

You have to know what character encoding is used in the txt file you are reading and then convert it to the encoding you want.

 

There are PHP features that you might find helpful doing this.

 

http://fi.php.net/iconv

http://fi.php.net/utf8_encode

http://fi.php.net/utf8_decode

 

And everything related to those functions. (Including user comments, there are some handy functions submitted)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.