0510ML Projects and portfolio

12Feb/100

Character encoding

When working on the Food Library for TULM I ran into a problem with character encoding. All æ, ø and å's were being transformed into wierd looking characters.
I needed a way to fix this issue, without the use of str_replace or something similar, since I was retrieving HTML pages with more than 4,000 lines - which would make the str_replace on 10 pages pretty resource intensive.

After looking on the InterGoogle, I found a good solution. PHP comes with a function called iconv.
The syntax for this function is

iconv ( string $in_charset , string $out_charset , string $str )

and by using the following code, this solved my problem and displayed all characters exactly as i wanted them.

$txt = iconv('UTF-8','ISO-8859-1',$txt);

I hope this will be useful to some, so you can avoid going emo due to wrong character encoding from remote sources ;)

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

You must be logged in to post a comment.

No trackbacks yet.