Jump to content

Archived

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

thebuzz

Convert UTF8 to danish letters... Not so simple as I thought

Recommended Posts

Hiya

I use utf8_decode to convert utf8 string feed to Danish iso-8859-1, which should be rather simple...

Feed string is forexample $news->body
ØK holder kursen

Which should turn into
ØK holder kursen

doing
utf8_decode(utf8_decode($news->body)) returns bad chars tho it converts lowercase æøå to the right letters, however capital letters ÆØÅ isnt converted.

Anyone has some suggestions?

I also do not understand why it has to be utf8_decode decoded twice...

Share this post


Link to post
Share on other sites
I'm not a guru at this, but my testing is below. As far as I know, I think your data is either corrupt or not UTF-8 encoded.
[code]
<pre>
<?php

$format = '%-30s=>%20s';
### Create an O slash.
$O_slash = pack("c*", 0xc3, 0x98);
printf($format, 'UTF-8 O slash', $O_slash);
echo '<br />';
### Decode it.
printf($format, 'Decoded O slash', utf8_decode($O_slash));
echo '<br />';
### Encode it? This is incorrect...
printf($format, 'Encoded encoded O slash', utf8_encode($O_slash));
echo '<br />';
### What the string should really be.
$should_be = $O_slash . 'K holder kursen';
printf($format, utf8_decode("'$should_be' should be"), $should_be);

?>
</pre>
[/code]

Share this post


Link to post
Share on other sites

×

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.