我想在php中读取一个json文件。将字符串作为变量处理。然后将格式良好的json文件输出到磁盘。但echo输出包含转义序列,我不想要。输出文件完全空白!那不应该。我该怎么办?
echo gives: "[\n { \n \"Class\": \"B\", \n \"Rating\": \"1600\", \n \"ID\": \"16733310\", \n \"Name\": \"Larrategui, Martin\", \n \"Expires\": \"\"\n }, ....etc. (This is not the nicely formatted json file I need.)
<?php
$file = file_get_contents("uscf.json");
$new = strtolower($file);
$new = str_replace('1000.10.10','',$new);
$myJSON = json_encode($new);
echo ($myJSON); //output gives the code below (x300) instead of a nicely formatted json.
//"[\n { \n \"Class\": \"B\", \n \"Rating\": \"1600\", \n \"ID\": \"16733310\", \n \"Name\": \"Larrategui, Martin\", \n \"Expires\": \"\"\n }, ....etc.
$myfile = fopen("uscf_mems.json", "w") or die("Unable to open file!");
fwrite($myfile,$myJSON); fclose($myfile); chmod($myfile,0777);