【问题标题】:Why PHP send binary 0x2EF5 but Javascript receive 0x2EFD?为什么 PHP 发送二进制 0x2EF5 而 Javascript 接收 0x2EFD?
【发布时间】:2015-06-18 13:07:33
【问题描述】:

我的 PHP 读取一个二进制文件并将其传输到 Javascript 客户端。不幸的是,我解析错误;例如,HEX 值 2EF5 的处理方式与 2EFD 类似。

PHP

echo file_get_contents($filepath);

JAVASCRIPT

function handleDatFile(data){
    var view = new jDataView(data, undefined, undefined, true);

    parser = new jParser(view, {
        header: {
            ID: 'uint32',
            sample: 'uint32',
            analogs: [
                'array', 
                function(){
                    var v0 = this.parse(16);
                    return v0.toString(2);
                },
                8
            ],
            digitals: ['array', 4, 29]
        }
    });
}

【问题讨论】:

    标签: javascript php file binary


    【解决方案1】:

    这个问题只能使用标题来解决。

    在 html 中

    或 在 php 中

    header('Content-Type: text/html; charset=utf-8');

    【讨论】:

    • 抱歉,您的解决方案不起作用。我尝试在 php 端添加 header('Content-Type: text/html; charset=utf-8'); ,在我的 $.ajax 中添加相同发布内容类型,但 0xF5 总是像 0xFD 一样被解析。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-11
    • 2011-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多