【发布时间】:2012-12-25 11:52:08
【问题描述】:
我以前认为这是100%:
file_put_contents ('cacheHere', json_encode($array));
但这只是 99%。它只能编码utf8编码的数据,所以:
file_put_contents ('cacheHere', json_encode(utf8_encode($array)));
仍然不行,因为 $array 是数组,而不是字符串。我知道我可以对一个字段进行 utf8 编码,但我需要一个通用的解决方案。
【问题讨论】:
-
你确定你首先需要
json_encode()吗? -
佩卡怎么说;也许
serialize/unserialize可能是这里的替代品。这处理了大量的 PHP 怪癖。