0

I'm having a hard time getting the "price" to be displayed. Am I using php the right way in this case?

<html>
<head>
<script src="http://code.jquery.com/jquery-1.12.0.min.js"></script>
</head>
<body>
<table width="100%">
<td>Bitstamp</td>

<?php
$url = "https://www.bitstamp.net/api/ticker/";
$fgc = file_get_contents($url);
$json = json_decode($fgc, true);
$price = $json["last"];
?>

<td><?php echo $price; ?></td>
</table>
</body>
</html>
5
  • 3
    Your code looks ok. What do you get? Does your server support PHP? Does your filename end in .php ? Anything in your error log? Commented Feb 6, 2017 at 22:25
  • Your <table> is missing a row <tr> but I don't think it would stop it working Commented Feb 6, 2017 at 22:26
  • Everything you mentioned seems to be in order, but I get nothing. All I see is the "Bitstamp" text. Commented Feb 6, 2017 at 22:38
  • 1
    Please answer my previous questions about your server, filename and logs Commented Feb 6, 2017 at 22:40
  • There was a problem with Wordpress reading the file. Using "Insert PHP" plugin fixed it. Thank you! Commented Feb 6, 2017 at 22:55

1 Answer 1

1

Yes, it's correct. If you don't get reply from file_get_contents function, you might want to set php setting allow_url_fopen=true

http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.