Jump to content


Photo

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


  • Please log in to reply
1 reply to this topic

#1 thebuzz

thebuzz
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 16 August 2006 - 01:25 PM

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

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 16 August 2006 - 01:54 PM

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

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users