简体   繁体   English

使用Javascript“ N.O.I.C.E。”显示文本时出现问题,php毫无问题地显示文本

[英]Problems with displaying text in Javascript “N�O�T�I�C�E�”, php displays it with no problem

PHP creates the text from metadata from image file which stores it in variable of the same name of IMG source. PHP从图像文件的元数据创建文本,并将其存储在与IMG源名称相同的变量中。 No Problems 没问题

JavaScript displays the gallery to show images, scroll & enlarge. JavaScript显示图库以显示图像,滚动和放大。
During enlargement it gives description of image from source attribute but always displays the text with after every character. 在放大过程中,它从源属性给出图像描述,但始终在每个字符后显示``。 But PHP doesn't. 但是PHP没有。

I've tried encoding which you will see from code & & echo header("Content-Type: text/html; charset=ISO-8859-1"); 我已经尝试编码,您将从代码&&echo标头中看到编码(“ Content-Type:text / html; charset = ISO-8859-1”);

PHP: 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\">');
   }); 

Sloppy but Works and window[v] is the call 马虎,但作品和window [v]是电话

Should display: this is the new val = NOTICE: This e-mail message may contain legally privileged and/or confidential information. 应该显示:这是新值val =注意:此电子邮件可能包含合法特权和/或机密信息。 If you are not the intended recipient, you are hereby notified that any dissemination of the contents of this message is strictly prohibited. 如果您不是预期的收件人,我们将特此通知您,严禁传播此消息的内容。 If you have received this message in error, please immediately notify the sender at ########### and delete all copies of this e-mail message and its attachments. 如果您错误地收到了此消息,请立即通过############通知发件人,并删除此电子邮件及其附件的所有副本。

Not: N O T I C E : T h i s e - m a i l m e s s a g e m a y c o n t a i n l e g a l l y p r i v i l e g e d a n d / o r c o n f i d e n t i a l i n f o r m a t i o n . I f y o u a r e n o t t h e i n t e n d e d r e c i p i e n t ,............... 否:N.O.I.C.E ... T.H.I.E.M.A.I.L.M.S.A.G就是一个c.o.c.o.t.i.l.g.a.l.l.p.r.v.i例如,``a.d.a.d.a.d.o.c.o.我不是我,而是我,我是一个人。 ``tée.d.d.d.d.d.r.c.i.p.i.t. .........

Never use utf8_encode() or utf8_decode() they make awful assumptions and happily/silently corrupt your data. 切勿使用utf8_encode()utf8_decode()它们会做出可怕的假设并会愉快/无声地破坏您的数据。 Always use a function that allows you to explicitly specify your input and output encodings. 始终使用允许您显式指定输入和输出编码的函数。

The data you're extracting from EXIF is encoded as UTF16-LE, and your page is... something else. 您从EXIF提取的数据被编码为UTF16-LE,而您的页面则是……。 I can't tell what and you should probably figure that out and be consistent. 我不知道该怎么办,您可能应该弄清楚并保持一致。

Suggested reading: UTF-8 all the way through 建议阅读: UTF-8贯穿始终

If your page is encoded as ISO-8859-1: 如果您的页面编码为ISO-8859-1:

$proper = mb_convert_encoding($input, 'ISO-8859-1', 'UTF-16-LE');

If your page is encoded as UTF-8: 如果您的页面编码为UTF-8:

$proper = mb_convert_encoding($input, 'UTF-8', 'UTF-16-LE');

Ref: https://secure.php.net/manual/en/function.mb-convert-encoding.php 参考: https : //secure.php.net/manual/en/function.mb-convert-encoding.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM