PHP – Write file in specific charset/encoding

Sometimes we need to specify the file charset before writing the data to a file. The data strings which we get from the database are in UTF-8 so we have to convert them in proper charset. This could be done be iconv().

For example, i want to write the Traditional Chinese in Big5. The conversion could be done by.

$big5_str = iconv('UTF-8', 'Big5', $utf8_str);

 

Done =)

Reference: StackOverflow – PHP – UTF-8 to Chinese ANSI (GB2312?) – Export CSV file

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.