簡體   English   中英

php exif_read_data() 不是 utf-8

[英]php exif_read_data() not in utf-8

所以我在foreach使用glob()函數來渲染我網站上文件夾中的圖像,我想在那里有標題,所以我把標題放在那個圖像的元數據中,但是當我通過 exif_read_data() 執行這些元數據時它不會在 utf-8 中執行,它會顯示 POL`T?XE this 而不是這個 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,但它也不起作用。 你能幫助我嗎?

經過數小時的尋找答案而沒有找到任何東西(對我來說沒有任何用處),我想出了這樣的方法:我將整個普通字母表和特殊字符字母表放入該圖片的元數據中,然后用$meta_data['IFD0']['Title']輸出它$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ř (與元數據相同)

注意:即使在$letters示例中,每個字符都必須與$hex位於相同的位置:

$letters = array('a', 'b', 'c', 'd');
$hex = array('6100','6200','6300','6400'); //'a', 'b', 'c', 'd'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM