将json格式字符串存到指定的php文件中
2018-08-21 本文已影响62人
peterz博客
存
function set_php_file($filename, $content){
$fp = fopen($filename, "w");
fwrite($fp, $content);
fclose($fp);
}
取
function get_php_file($filename){
return trim(substr(file_get_contents($filename), 15));
}
调用
$filename = "json/navs.json";
$content = json_encode($data);
set_php_file($filename,$content);
json_decode(get_php_file($filename));