note 105025 modified in function.iptcparse by danbrown

From: Date: Mon, 25 Jul 2011 12:29:43 +0000
Subject: note 105025 modified in function.iptcparse by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-181836@lists.php.net to get a copy of this message
Nowadays IPTC captions may be encoded in UTF-8. In that case, IPTC tag CodedCharacterSet would be set to "ESC % G". This tag has tag marker "1#090". To decode such a caption into simple ISO-8859-1, you could use the following code: <?php $IPTC_Caption = ""; $size = getimagesize( $image_path, $info ); if (isset($info["APP13"])) { if($iptc = iptcparse( $info["APP13"] ) ) { $IPTC_Caption = str_replace( "\000", "", $iptc["2#120"][0] ); if(isset($iptc["1#090"]) && $iptc["1#090"][0] == "\x1B%G") $IPTC_Caption = utf8_decode($IPTC_Caption); } } ?> Of course, this will only preserve ISO-8859-1 characters. For proper Unicode support, you should convert UTF-8 byte sequences into HTML character entities, or encode the whole web page in UTF-8. --was-- Nowadays IPTC captions may be encoded in UTF-8. In that case, IPTC tag CodedCharacterSet would be set to "ESC % G". This tag has tag marker "1#090". To decode such a caption into simple ISO-8859-1, you could use the following code: $IPTC_Caption = ""; $size = getimagesize( $image_path, $info ); if (isset($info["APP13"])) { if($iptc = iptcparse( $info["APP13"] ) ) { $IPTC_Caption = str_replace( "\000", "", $iptc["2#120"][0] ); if(isset($iptc["1#090"]) && $iptc["1#090"][0] == "\x1B%G") $IPTC_Caption = utf8_decode($IPTC_Caption); } } Of course, this will only preserve ISO-8859-1 characters. For proper Unicode support, you should convert UTF-8 byte sequences into HTML character entities, or encode the whole web page in UTF-8. http://php.net/manual/en/function.iptcparse.php

« previous php.notes (#181836) next »