将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));
上一篇下一篇

猜你喜欢

热点阅读