PHP exif_read_data()不在utf-8中

时间:2018-08-18 19:58:15

标签: php html encoding utf-8 exif

因此,我正在glob()中使用foreach函数从网站上的文件夹渲染图像,并且我希望在其中放置标题,因此我将标题放在该图像的元数据中,但是当我通过exif_read_data()执行这些元数据,它将不在utf-8中执行,它显示POL`T?XE而不是此POLŠTÁŘE。 这是我的代码,尝试解决此问题

header("Content-Type: text/html; charset=utf-8");
ini_set('exif.encode_unicode', 'UTF-8');
iconv_set_encoding('input_encoding', 'UTF-8');
iconv_set_encoding('output_encoding', 'UTF-8');
iconv_set_encoding('internal_encoding', 'UTF-8');

$dirs = array_filter(glob('img/*'), 'is_dir');
foreach ($dirs as $dir) {
  $files = glob($dir.'/*.{jpg,png,JPG,PNG,jpeg,JPEG}', GLOB_BRACE);
  foreach($files as $file) {
    $meta_data = exif_read_data($file, 0, true);
    echo '
    <img src="'.$file.'" title="'.$meta_data['IFD0']['Title'].'" />
    ';
  }
}

即使我使用exiftools,也没有任何效果。 甚至没有utf8_encode(),甚至没有mb_convert_encoding($meta_data['IFD0']['Title'], 'UTF-8')。 当我使用此mb_detect_encoding()函数时,它执行了UTF-8。

然后我尝试使用exiftool将编码设置为utf-8,但也没有用。你能帮我吗?

1 个答案:

答案 0 :(得分:0)

经过数小时的寻找答案却什么都没找到(对我没有任何帮助)后,我发现是这样的:我将整个普通字母和特殊字符字母放入图片的元数据中,然后用{{1 }}到$meta_data['IFD0']['Title']函数,并为每个字母和特殊字母制作bin2hex(),然后用array用普通字符替换代码。

str_replace

$hex = array('0000','6100','6200','6300','6400','6500','6600','6700','6800','6900','6a00','6b00','6c00','6d00','6e00','6f00','7000','7100','7200','7300','7400','7500','7600','7700','7800','7900','7a00','4100','4200','4300','4400','4500','4600','4700','4800','4900','4a00','4b00','4c00','4d00','4e00','4f00','5000','5100','5200','5300','5400','5500','5600','5700','5800','5900','5a00','e100','0d01','0f01','e900','1b01','ed00','4801','f300','5901','6101','6501','fa00','6f01','fd00','7e01','c100','0c01','0e01','c900','1a01','cd00','4701','d300','5801','6001','6401','da00','6e01','dd00','7d01','2c00', '2000','3100','3200','3300','3400','3500','3600','3700','3800','3900','3000','2d00','2100','2b00');

$letters = array('', 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','á','č','ď','é','ě','í','ň','ó','ř','š','ť','ú','ů','ý','ž','Á','Č','Ď','É','Ě','Í','Ň','Ó','Ř','Š','Ť','Ú','Ů','Ý','Ž', ',', ' ','1','2','3','4','5','6','7','8','9','0','-','!','+');

之前的输出:str_replace($hex, $letters, bin2hex($meta_data['IFD0']['Title']))

以下之后的输出:aY45Y5~1a534Y68Y(与元数据相同)

注意:即使在šěř45čř5ž1š53čě4ř6ě8ř示例中,每个字符也必须与$hex中的位置相同:

$letters