-1

I do not know any PHP but I'm trying to make a page to just echo a result which I can then use as a conky config.

This is what I have tried

<?php  
$content=file_get_contents("https://btc-e.com/api/2/ltc_usd/ticker");
$data=json_decode($content);

echo "Current Price: $";
echo $data->ticker->avg;;
?>

But I just get "Current Price: $" without the actual price.

Any help is appreciated, thanks!

4
  • Try var_dump($data); Commented Sep 9, 2014 at 21:49
  • Thanks however I got Current Price: $NULL when adding this, I put it at the end not sure if thats where it should of been. Thanks Commented Sep 9, 2014 at 21:53
  • So it means, there is no json encoded output in this URL. Commented Sep 9, 2014 at 21:55
  • That means $data is NULL. You likely do not have valid JSON Commented Sep 9, 2014 at 22:09

1 Answer 1

2

First of all, I am assuming you're new to PHP. Welcome. In the future, you should perform the following steps before you even start asking for help.

  1. Enable PHP error messages
  2. Look at the error messages if any
  3. Dump the variable(s) that aren't behaving as expected
  4. You'll probably have your answer by now
  5. If not, then ask for help

In your case it's most likely because you have the PHP setting allow_url_fopen set to Off. Set it to On in your php.ini config file.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi thanks for this, I was just doing it all from a text editor then ftping it to my test site, so I dont even have a php.ini maybe this is my issue.. Thanks
If you're using shared hosting, you're out of luck. You'll need to fetch the content using cURL instead stackoverflow.com/questions/21642604/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.