php - get JSON from long string -


since host doesn't allow file_get_contents must use else api call. got code content of website:

function get_contents_by_uri($uri) { $urielem = parse_url ( $uri ); $fp = @fsockopen ( $urielem ['host'], 80, $errno, $errstr, 10 );  if (! $fp) {     throw new exception ( "could not create socket: '" . $errnstr . "' (" . $errno . ")." ); }  $request = "get " . $urielem ['path'] . (isset ( $urielem ['query'] ) ? "?" . $urielem ['query'] : "") . " http/1.1\r\n"; $request .= "host: " . $urielem ['host'] . "\r\n"; $request .= "connection: close\r\n\r\n";  fwrite ( $fp, $request ); $response = ""; while ( ! feof ( $fp ) ) {     $response .= fgets ( $fp, 128 ); } fclose ( $fp );  // split headers data $responsesplit = explode ( "\r\n\r\n", $response, 2 );  return $responsesplit [1]; } 

this works fine simple call: http://dogechain.info/chain/dogecoin/q/getblockcount

but adds data calls containing json.

example:

if use get_contents_by_uri() on http://data.bter.com/api/1/ticker/doge_btc, don't get

{"result":"true","last":"0.00000188","high":"0.00000191","low":"0.00000185","avg":"0.00000188","sell":"0.00000189","buy":"0.00000188","vol_doge":82094227.628,"vol_btc":154.34039658} 

but

b6 {"result":"true","last":"0.00000188","high":"0.00000191","low":"0.00000185","avg":"0.00000188","sell":"0.00000189","buy":"0.00000188","vol_doge":82094227.628,"vol_btc":154.34039658} 0 

how sole json part of string?

i'm not sure why (so far), using http/1.0 instead of http/1.1 works me.
(i found lurking internet , trying other solutions.)


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -