I am trying to read this JSON file, which I checked is valid
https://www.webminepool.com/api/PK_MgGG3Z8joogwr28PmkE9i/wmc_rate/1000
Here is my code:
//normally the rate is changed via PHP
$checkbtc = "https://www.webminepool.com/api/PK_MgGG3Z8joogwr28PmkE9i/wmc_rate/1000";
$json = file_get_contents($checkbtc);
$json = utf8_encode($json);
$json_data = json_decode($json,true);
print('<br>...'.$json_data.'...<br>');
var_dump($json_data);
The file in my browser sends :
{"success":true,"satoshi":"26.936"}
which seems correct
The result when I execute php is :
<br>......<br>
So where am I wrong ???
Thanks
file()
file_get_contents()
with or without utf8_encode
STUCK
2
Answers
Seems like the endpoint is doing some checks to validate your user-agent, you better to use cURL with it.
Check that here you are getting valid JSON string.
Remove this line. No need and is deprecated method as well.
From here tested and works.
returns:
utf8_encode — This function is deprecated as of PHP 8.2.0.
Alternative: mb_convert_encoding(), which supports ISO-8859-1 and many other encodings.
Alternative way to get content from APi point: