m939594960
V2EX  ›  问与答

laravel pajx 的一个编码问题

  •  
  •   m939594960 · Apr 10, 2016 · 1987 views
    This topic created in 3769 days ago, the information mentioned may be changed or developed.
    在 laravel 用 https://github.com/spatie/laravel-pjax 来实现 pjax

    现在出现一个非常蛋疼的问题
    就是页面上 普通的元素编码没有问题
    但是<script></script>中的中文都会出现编码错误


    而去掉 script 标签一切都会正常



    后来大概发现问题出现在这 可能是 Symfony Crawler 的问题 /bug ?


    到底 bug 还是我用法上的问题
    谢谢大家的帮助~~
    Supplement 1  ·  Apr 10, 2016
    暂时找到一个不是很完美的解决方案
    http://stackoverflow.com/questions/27049398/domdocument-savehtml-escape-utf8-in-script-tag

    $newContent = preg_replace_callback("/(&#[0-9]+;)/", function($m) {
    return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES");
    }, $newContent);
    就是用正则把编码不对的字符替换
    1 replies    2017-08-24 11:26:43 +08:00
    mandex
        1
    mandex  
       Aug 24, 2017
    这个问题我也遇到了,没想到过了 500 天还没有修复,你现在有更好的解决办法了吗?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3007 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 14:17 · PVG 22:17 · LAX 07:17 · JFK 10:17
    ♥ Do have faith in what you're doing.