Jump to content

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


thebuzz

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...
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.