本文介绍了使用exif_read_data获取元数据表单图像时编码错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用exif_read_data函数从上传的图像中获取评论信息。
我想将此信息插入相应的图片 alt标签中。插入的值看起来像这样:
T.r.a.v.e.l。

I'm getting the 'Comments' information from a uploaded image with the exif_read_data function.I want to insert this information into the corresponding image 'alt' tag. The inserted value looks like this:T�r�a�v�e�l���

我尝试了几种编码变体,但无法

I tried several encoding variants but i can't get a proper string.

PHP:

$exif = exif_read_data($dir.$image , 0 ,true);
$rel  = $exif["IFD0"]["Comments"];

HTML:

<img alt='$rel' src='test.jpg' />

输出:
像这样...

OUTPUT:something like this...

<img alt='T�r�a�v�e�l��� ' src='test.jpg' />

html页面的实际编码为UTF-8

The actual encoding for the html page is UTF-8

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>


推荐答案

我不知道是否能解决您的问题(如果是,请在这里告诉我)。但是在上有一个注释,其中包含php.ini配置以设置exif编码:

I don't know if will solve your problem (if yes, let me know here). But there's a comment at php.net with a php.ini config to set the exif encoding:

<?php
ini_set('exif.encode_unicode', 'UTF-8');
?>

这篇关于使用exif_read_data获取元数据表单图像时编码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 08:13