PHP. Strange numbers in the end of JSON -



PHP. Strange numbers in the end of JSON -

i reading , saving weather json info forecast.io api. because using free api has 1000 requests limit per day. requesting api every 10 minutes. saving update time timestamp , using timestamp check 10 minutes elapsed or not. when reading json file , echoing it, unusual number '18706' or '22659' coming out. not have thought coming from. how solve problem?

result in browser:

....madis-stations":["uttt"],"units":"si"}}22659

php:

<?php $t = time(); $last_updated_timestamp = file_get_contents("last_updated_timestamp.txt"); $delta = ($t - $last_updated_timestamp) / 60; if ($delta > 10) { $json = file_get_contents('https://api.forecast.io/forecast/my_api_key/41.2667,69.2167?units=si&lang=ru'); $obj = json_decode($json); echo $obj->access_token; $fp = fopen('tw.json', 'w'); fwrite($fp, json_encode($obj)); fclose($fp); $fp2 = fopen('last_updated_timestamp.txt', 'w'); fwrite($fp2, $t); fclose($fp2); } echo readfile("tw.json"); ?>

change:

echo readfile("tw.json");

to just:

readfile("tw.json");

readfile writes contents of file output buffer, , returns number of bytes wrote. you're echoing number of bytes.

it seems confused readfile file_get_contents, returns contents of file string.

php json

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -