将json格式字符串存到指定的php文件中

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));

你可能感兴趣的:(将json格式字符串存到指定的php文件中)