html 标签属性内的字符显示为问号

2024-03-27

我的应用程序允许用户上传带有“嵌入”标题的图像。这些标题取自 exif 数据:

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

图像与其标题一起显示。每个图像的标题都会渲染 2 次:

  1. title的属性<a>包裹在图像周围
  2. in a div包含标题的

这是结果:

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

正如你所看到的,当标题位于title属性,出现问号。为什么会这样呢?

我要指出的是,我已经使整个应用程序使用 utf8(数据库、html 页面)。我也尝试过utf8_encode()在将其保存到数据库之前提取的标题,但无济于事。

有任何想法吗?

EDIT:顺便说一下,使用的原因<a>以便单击时图像出现在 jQuery 灯箱中。

EDIT:@tpaksu,这是结果的实际转储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)
        )

)

Windows 7 似乎使用 UTF-16 Little Endian 对 IFD0 标签进行编码,因此您也可以尝试使用以下命令解析这些值iconv() and trim()结果字符串万一:

$exif_data = exif_read_data( $file, NULL, true, false );
    if ( isset( $exif_data['IFD0'] ) ) {
        $title  = trim(iconv('UTF-16LE','UTF-8',$ifd0['Title']));
    }

当然,明智的做法是确保您的系统提供 UTF-16LE 和 UTF-8

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

html 标签属性内的字符显示为问号 的相关文章

随机推荐