My application allows users to upload an image with “embedded” captions. These captions are taken from the exif data:
foreach (exif_read_data('image.jpg', 0, true) as $key => $section) {
foreach ($section as $name => $val) {
if ($key == 'IFD0' && $name == 'Title') {
$caption = $val;
break;
}
}
if ($caption !== '') { break; }
}
//save $caption to database
The images are displayed along with their captions. Each image’s caption is rendered 2 times:
titleattribute of an<a>that is wrapped around the image- in a
divthat contains the caption
This is the result:
<a title="T?h?i?s? ?i?s? ?a? ?c?a?p?t?i?o?n?" href="#"><img src="image.jpg"></a>
<div class="caption">This is a caption.</div>
As you can see, when the caption is inside the title attribute, question marks appear. Why is this so?
I would note that I have made the whole application work with utf8 (database, html pages). I have also tried to utf8_encode() the extracted caption before saving it into the database, to no avail.
Any ideas?
EDIT:
By the way, the reason for using an <a> is so that the image appears in a jQuery lightbox when clicked.
EDIT:
@tpaksu, here is an actual dump of the result of exif_read_data('image.jpg', 0, true)
Array
(
[FILE] => Array
(
[FileName] => 174.jpg
[FileDateTime] => 1332196128
[FileSize] => 236179
[FileType] => 2
[MimeType] => image/jpeg
[SectionsFound] => ANY_TAG, IFD0, EXIF, GPS, WINXP
)
[COMPUTED] => Array
(
[html] => width="640" height="427"
[Height] => 427
[Width] => 640
[IsColor] => 1
[ByteOrderMotorola] => 1
[CCDWidth] => 9mm
[ApertureFNumber] => f/11.0
[UserComment] =>
[UserCommentEncoding] => UNDEFINED
)
[IFD0] => Array
(
[ImageDescription] => STATE OF CALAMITY/FEB. 2, 2012: Firemen and residents of sitio San Roque in Talisay City help each other in putting off the fire. The Talisay City council wants to declare sitio Laray in a state of calamity.(CDN PHOTO/JUNJIE MENDOZA)
[Make] => Canon
[Model] => Canon EOS 50D
[Orientation] => 1
[Software] => Adobe Photoshop CS2 Windows
[DateTime] => 2012:02:04 18:54:15
[YCbCrPositioning] => 1
[UndefinedTag:0x1001] => 4752
[UndefinedTag:0x1002] => 3168
[Exif_IFD_Pointer] => 2544
[GPS_IFD_Pointer] => 5304
[Title] => S�T�A�T�E� �O�F� �C�A�L�A�M�I�T�Y�/�F�E�B�.� �2�,� �2�0�1�2�:� �F�i�r�e�m�e�n� �a�n�d� �r�e�s�i�d�e�n�t�s� �o�f� �s�i�t�i�o� �S�a�n� �R�o�q�u�e� �i�n� �T�a�l�i�s�a�y� �C�i�t�y� �h�e�l�p� �e�a�c�h� �o�t�h�e�r� �i�n� �p�u�t�t�i�n�g� �o�f�f� �t�h�e� �f�i�r�e�.� �T�h�e� �T�a�l�i�s�a�y� �C�i�t�y� �c�o�u�n�c�i�l� �w�a�n�t�s� �t�o� �d�e�c�l�a�r�e� �s�i�t�i�o� �L�a�r�a�y� �i�n� �a� �s�t�a�t�e� �o�f� �c�a�l�a�m�i�t�y�.�(�C�D�N� �P�H�O�T�O�/�J�U�N�J�I�E� �M�E�N�D�O�Z�A�)���
[Subject] => S�T�A�T�E� �O�F� �C�A�L�A�M�I�T�Y�/�F�E�B�.� �2�,� �2�0�1�2�:� �F�i�r�e�m�e�n� �a�n�d� �r�e�s�i�d�e�n�t�s� �o�f� �s�i�t�i�o� �S�a�n� �R�o�q�u�e� �i�n� �T�a�l�i�s�a�y� �C�i�t�y� �h�e�l�p� �e�a�c�h� �o�t�h�e�r� �i�n� �p�u�t�t�i�n�g� �o�f�f� �t�h�e� �f�i�r�e�.� �T�h�e� �T�a�l�i�s�a�y� �C�i�t�y� �c�o�u�n�c�i�l� �w�a�n�t�s� �t�o� �d�e�c�l�a�r�e� �s�i�t�i�o� �L�a�r�a�y� �i�n� �a� �s�t�a�t�e� �o�f� �c�a�l�a�m�i�t�y�.�(�C�D�N� �P�H�O�T�O�/�J�U�N�J�I�E� �M�E�N�D�O�Z�A�)���
[UndefinedTag:0xEA1C] => �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
)
[EXIF] => Array
(
[ExposureTime] => 1/125
[FNumber] => 11/1
[ISOSpeedRatings] => 400
[ExifVersion] => 0221
[DateTimeOriginal] => 2012:02:02 12:40:00
[DateTimeDigitized] => 2012:02:02 12:40:00
[ComponentsConfiguration] => �
[ShutterSpeedValue] => 458752/65536
[ApertureValue] => 458752/65536
[ExposureBiasValue] => 0/1
[Flash] => 16
[FocalLength] => 16/1
[UserComment] => ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
[SubSecTimeOriginal] => 00
[SubSecTimeDigitized] => 00
[FlashPixVersion] => 0100
[ColorSpace] => 1
[ExifImageWidth] => 2000
[ExifImageLength] => 1333
[FocalPlaneXResolution] => 4752000/894
[FocalPlaneYResolution] => 3168000/597
[FocalPlaneResolutionUnit] => 2
[CustomRendered] => 0
[ExposureMode] => 1
[WhiteBalance] => 0
[SceneCaptureType] => 0
[UndefinedTag:0xEA1C] => �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
)
[GPS] => Array
(
[GPSVersion] => ��
)
[WINXP] => Array
(
[Title] => STATE OF CALAMITY/FEB. 2, 2012: Firemen and residents of sitio San Roque in Talisay City help each other in putting off the fire. The Talisay City council wants to declare sitio Laray in a state of calamity.(CDN PHOTO/JUNJIE MENDOZA)
[Subject] => STATE OF CALAMITY/FEB. 2, 2012: Firemen and residents of sitio San Roque in Talisay City help each other in putting off the fire. The Talisay City council wants to declare sitio Laray in a state of calamity.(CDN PHOTO/JUNJIE MENDOZA)
)
)
Ok try this inside your code.
or