Preferred method to store PHP arrays (json_encode vs serialize)

前端 未结 20 1925
孤独总比滥情好
孤独总比滥情好 2020-11-22 05:55

I need to store a multi-dimensional associative array of data in a flat file for caching purposes. I might occasionally come across the need to convert it to JSON for use in

20条回答
  •  难免孤独
    2020-11-22 06:43

    JSON is better if you want to backup Data and restore it on a different machine or via FTP.

    For example with serialize if you store data on a Windows server, download it via FTP and restore it on a Linux one it could not work any more due to the charachter re-encoding, because serialize stores the length of the strings and in the Unicode > UTF-8 transcoding some 1 byte charachter could became 2 bytes long making the algorithm crash.

提交回复
热议问题