PDA

View Full Version : help on utf-8


jdleung
04-01-2006, 06:36 PM
I'm using Chinese for the image title(IPTC CAPTION),and today I found the addon pp_iptc.php cannot display Chinese correctly when the browser set to UTF-8.

how can I convert characters to UTF-8?

Can help?

Thanks.

Connie
04-01-2006, 07:46 PM
who wrote this AddOn? I would suggest to contact the author

all PP AddOns should be utf-8-compliant, of course, so it would be good to tell him about this and ask for an update..

jdleung
04-02-2006, 03:54 AM
who wrote this AddOn? I would suggest to contact the author

all PP AddOns should be utf-8-compliant, of course, so it would be good to tell him about this and ask for an update..

Connie, the addon can be download at pixelpost addon site. I use acdsee to enter image caption on windows xp.

and I download codes on the web:

// utf8 -> unicode
function utf8_unicode($c) {
switch(strlen($c)) {
case 1:
return ord($c);
case 2:
$n = (ord($c[0]) & 0x3f) << 6;
$n += ord($c[1]) & 0x3f;
return $n;
case 3:
$n = (ord($c[0]) & 0x1f) << 12;
$n += (ord($c[1]) & 0x3f) << 6;
$n += ord($c[2]) & 0x3f;
return $n;
case 4:
$n = (ord($c[0]) & 0x0f) << 18;
$n += (ord($c[1]) & 0x3f) << 12;
$n += (ord($c[2]) & 0x3f) << 6;
$n += ord($c[3]) & 0x3f;
return $n;
}
}

preg_match_all("/[\x80-\xff]?./",$iptc_caption,$ar);
foreach($ar[0] as $v)
echo "&#".utf8_unicode(iconv("GB2312","UTF-8",$v)).";";
$iptc_caption = "&#".utf8_unicode(iconv("GB2312","UTF-8",$v)).";";

$tpl = str_replace("<IPTC_CAPTION>",$iptc_caption,$tpl);

"echo" displays the whole caption.
the last line only show the last character of the caption. I think it something about "foreach".

Thanks.

jdleung
04-02-2006, 08:00 AM
I found the Calendar addon developed by pixelpost team doesn't support gb2312 too.

I use the language-variables in language file,also displays in a mess.
I know little abut this. is it only convert a certain language to utf-8? but not all?

GeoS
04-02-2006, 08:41 AM
You've got answer on PM for second from end post. About calendar addon - it should support UTF-8 but maybe converting from one system to second is problem. Try to encode whole data in UTF-8.

jdleung
04-04-2006, 04:10 AM
now I found it also works using only a funtion "iconv"
$iptc_caption_utf8 = iconv("GB2312","UTF-8",$iptc_caption);

but the codes I used before can display Chinese whether the browser set to gb2312 or utf-8.

raminia
04-04-2006, 09:03 AM
I'm the original writer of that addon. btw, I don't know what to do to support that. actually that addon was provided as a sample. I'm not supporting that kind of addons anymore ('cause there are lots of addons that I wrote that way).

anyway, I think you could first encode the caption content completely by something like base64 encoding then extract it and decode it. maybe this does not work at all but its an bare idea.... ;)

jdleung
04-04-2006, 05:44 PM
I'm the original writer of that addon. btw, I don't know what to do to support that. actually that addon was provided as a sample. I'm not supporting that kind of addons anymore ('cause there are lots of addons that I wrote that way).

anyway, I think you could first encode the caption content completely by something like base64 encoding then extract it and decode it. maybe this does not work at all but its an bare idea.... ;)

now the codes works ok. I don't want to go too far. I know nothing about encoding and decoding.

Thanks.