PHP 根据图像文件的元数据创建文本,并将其存储在与 IMG 源同名的变量中。 没问题
JavaScript 显示图库以显示图像、滚动和放大。
在放大过程中,它会根据源属性给出图像的描述,但始终在每个字符后显示带有 � 的文本。但 PHP 没有。
我已经尝试过编码,您将从代码中看到 & & echo header("Content-Type: text/html; charset=ISO-8859-1");
PHP:
$path = "gallery/";
$objs = new RecursiveIteratorIterator(new
RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::SELF_FIRST);
$num = 0;
foreach ($objs as $pic){
$pic = str_replace('gallery/', '', $pic);
if ($pic == '..' or $pic == '.'){
continue;
}
$exif = exif_read_data("$DIR/gallery/$pic", 0, true);
$pic = str_replace('.JPG', '', $pic);
${$pic} = $exif['IFD0']['Comments']; ///// php Variable
echo "<script> var $pic = '".$exif['IFD0']['Comments']."';
var $pic = utf8_encode($pic);</script>";
// JS of variable of same name.
}
Sloppy but Works
JQuery:
$('#mSide').on('click',function(){
var src = $('#mPic').attr('src');
var v = src.replace('/gallery/','');
v = v.replace('.JPG','');
v = unescape(encodeURIComponent(v));
$('#fullPic').show();
$('#fullPic').append('<img class=\"fPic\" src=\"'+src+'\"
height=\"90%\" widdth=\"90%\" style=\"margin-left:0px;\" />');
$('#fullPic').append('<span id=\"picSummary\"
style=\"color:#FFFFFF;\" >testing <textarea > '+ window[v] +'</textarea>
</span>');
$('#fullPic').prepend('<input class=\"closeFullP headr\"
value=\"Close\" READONLY><br class=\"closeFullP\">');
});
马虎但有效,window[v] 是调用
应显示:这是新的 val = 注意:此电子邮件可能包含法律特权和/或 secret 信息。如果您不是预期的收件人,特此通知您,严禁传播此消息的内容。如果您错误地收到此邮件,请立即通过 ########### 通知发件人,并删除此电子邮件及其附件的所有副本。
不是:N�O�T�I�C�E�:�“T�h�i�s�e�-�m�a�i�l” “我”向“我”“结婚” 之前的约会/约会 “确认与我的关系不相符。” “如果你”不"is" ………………………………………………………………………………………………………………………………………………………………………………………… ..
最佳答案
永远不要使用utf8_encode()
或utf8_decode()
,它们会做出糟糕的假设并愉快/默默地破坏您的数据。始终使用允许您显式指定输入和输出编码的函数。
您从 EXIF 中提取的数据被编码为 UTF16-LE,而您的页面是...其他东西。我不知道是什么,你应该弄清楚并保持一致。
建议阅读:UTF-8 all the way through
如果您的页面编码为 ISO-8859-1:
$proper = mb_convert_encoding($input, 'ISO-8859-1', 'UTF-16-LE');
如果您的页面编码为 UTF-8:
$proper = mb_convert_encoding($input, 'UTF-8', 'UTF-16-LE');
引用号:https://secure.php.net/manual/en/function.mb-convert-encoding.php
关于javascript - 在 Javascript "N�O�T�I�C�E�"中显示文本时出现问题,php 显示它没有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54486717/