Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 24th, 2014, 10:23 AM
Registered User
 
Join Date: May 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Pull Arrays from API

Hi people,

I'm using this very small script to pull and display some API info from either bitstamp.net/api/ticker/ and blockchain.info/ticker APIs. The script is currently pulling the info from Mt Gox but it's no longer working because they are out of business. Any help fixing this would be greatly appreciated. This is for a site I'm designing for a client: BitcoinValues.net.

Thank you

Code:
1.<?php
 2.          //first fetch the current rate from MtGox
 3.          $ch = curl_init('https://mtgox.com/api/0/data/ticker.php');
 4.                  curl_setopt($ch, CURLOPT_REFERER, 'Mozilla/5.0 (compatible; MtGox PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
 5.                  curl_setopt($ch, CURLOPT_USERAGENT, "CakeScript/0.1");
 6.                  curl_setopt($ch, CURLOPT_HEADER, 0);
 7.                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 8.                  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
 9.                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 10.                  $mtgoxjson = curl_exec($ch);
 11.                  curl_close($ch);
 12. 
 13.          //decode from an object to array
 14.                  $output_mtgox = json_decode($mtgoxjson);
 15.                  $output_mtgox_1 = get_object_vars($output_mtgox);
 16.                  $mtgox_array = get_object_vars($output_mtgox_1['ticker']);
 17. 
 18.  ?>
 19.  <br/>
 20.  <br/>
 21.  Last:&nbsp;<?php echo $mtgox_array['last'];   ?><br/>
 22.  High:&nbsp;<?php echo $mtgox_array['high'];   ?><br/>
 23.  Low:&nbsp;&nbsp;<?php echo $mtgox_array['low'];   ?><br/>
 24.  Avg:&nbsp;&nbsp;&nbsp;<?php echo $mtgox_array['avg'];   ?><br/>
 25.  Vol:&nbsp;&nbsp;&nbsp;<?php echo $mtgox_array['vol'];   ?><br/>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Facebook api vs Twitter api aspless Classic ASP Basics 4 September 11th, 2017 08:51 AM
Difference between lightweight BC api and the other normal API? boy18nj BOOK: Beginning Cryptography with Java 2 June 19th, 2011 08:13 PM
Multidemmesional Arrays OR arrays gmoney060 Classic ASP Basics 3 November 1st, 2004 03:42 PM
Pull or Push? sureshvb Crystal Reports 0 August 23rd, 2004 01:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.