WayToGo
V2EX  ›  PHP

[求助] JSON 文件格式化输出

  •  
  •   WayToGo · Dec 20, 2015 · 3850 views
    This topic created in 3804 days ago, the information mentioned may be changed or developed.

    本来看起来结构清晰的 JSON 文件(有换行和缩进),在被如下程序更新之后就变成只有一行了. 有什么办法让缩进换行结构保持不变吗?谢谢。
    $updatedContent = json_encode($tables);
    file_put_contents($file, $updatedContent);

    4 replies    2015-12-21 14:08:29 +08:00
    cxbig
        1
    cxbig  
       Dec 20, 2015   ❤️ 3
    输出的时候加个参数 JSON_PRETTY_PRINT
    WayToGo
        2
    WayToGo  
    OP
       Dec 20, 2015
    @cxbig 非常感谢!
    zonghua
        3
    zonghua  
       Dec 21, 2015
    @cxbig PHP 真面向对象语言,竟然这么多常量。
    cxbig
        4
    cxbig  
       Dec 21, 2015
    @zonghua 这些传统 fn 还要很长时间过度
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1175 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 17:46 · PVG 01:46 · LAX 10:46 · JFK 13:46
    ♥ Do have faith in what you're doing.