Get Json and output to text file undecoded

Posted by Gary on Stack Overflow See other posts from Stack Overflow or by Gary
Published on 2010-06-16T18:55:00Z Indexed on 2010/06/16 19:22 UTC
Read the original article Hit count: 273

Filed under:
|
|
|
|

Hi, I want to fetch json script and write it to a txt file undecoded, exactly how it was originally. I do have a script that I use that I am modifying but unsure what to commands to use. This script decodes, which is what I want to advoid.

//Get Age  
 list($bstat,$bage,$bdata) = explode("\t",check_file('./advise/roadsnow.txt',60*2+15));  
//Test Age  
if ( $bage > $CacheMaxAge ) {  
  //echo "The if statement evaluated to true so get new file and reset $bage";  


    $bage="0";  
    $file = file_get_contents('http://somesite.jsontxt');  
    $out = (json_decode($file));  
    $report = wordwrap($out->mainText, 100, "\n");   
    //$valid = $out->validTo;  
    //write the data to a text file called roadsnow.txt  
    $myFile = "./advise/roadsnow.txt";  
    $fh = fopen($myFile, 'w') or die("can't open file");  
    $stringData = $report;  
    fwrite($fh, $stringData);  
}  
else {  
  //echo the test evaluated to false; file is not stale so read local cache  
  //print "we are at the read local cache";  
  $stringData = file_get_contents("./advise/roadsnow.txt");  
}  
// if/else is done carry on with processing  
//Format file  
$data = $stringData  

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript