user1789437
user1789437

Reputation: 468

Get JSON data from API into string

Im trying to get some data into a string from an API..

<?php
 // create curl resource 
        $ch = curl_init(); 

        // set url 
        curl_setopt($ch, CURLOPT_URL, "https://api.feathercoin.com/?output=usd"); 

        //return the transfer as a string 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

        // $output contains the output string 
        $result = curl_exec($ch); 


        // Will dump a beauty json :3
        var_dump(json_decode($result, true));
        // close curl resource to free up system resources 
        curl_close($ch);  
?>

The above gives me: array(1) { ["usd"]=> float(1.210935) }

Now all I need to do is get the 1.210935 into a string of $coinvalue. Can anyone help me do this?!!

Thank you Jason

Upvotes: 0

Views: 220

Answers (1)

user1777136
user1777136

Reputation: 1756

$result = json_decode($result, true);
$coinvalue = (string) $result["usd"];

Upvotes: 1

Related Questions