简体   繁体   English

Json_decode 没有从数组中获取值

[英]Json_decode is not taking values from an array

I am absolute beginner in PHP, but some years ago I managed to create this simple code which calculates the daily price of copper in Bulgarian leva (BGN)我是 PHP 的绝对初学者,但几年前我设法创建了这个简单的代码,用于计算保加利亚列瓦 (BGN) 中铜的每日价格

Unfortunately today I found out that the variable $copper_lv_per_ton is empty and does not return anything不幸的是,今天我发现变量$copper_lv_per_ton是空的并且没有返回任何东西

$copper_data = json_decode(file_get_contents('https://www.quandl.com/api/v3/datasets/LME/PR_CU.json?limit=1&api_key=nXWf2HdsDzw6b4LK-moU'), true);
$currency_data = json_decode(file_get_contents('https://openexchangerates.org/api/latest.json?app_id=248e0a098c90432aabd9f17c98f9a030'), true);
$copper_lv_per_ton = $copper_data['dataset']['data'][0][2]*$currency_data['rates']['BGN'];

Thank you for your support!谢谢您的支持!

I am really trying to solve it for hours and cannot find what is going on我真的想解决它几个小时,却找不到发生了什么

在此处输入图像描述

The problem appeared from my Joomla website, where I get the variables and used them in a formula without seeing any errors or debug happening.问题出现在我的 Joomla 网站上,我在其中获取变量并在公式中使用它们,而没有看到任何错误或调试发生。

Then I tried the code in the W3Schools compiler and it was not working again.然后我尝试了 W3Schools 编译器中的代码,但它不再工作了。 Then @KIKO Software suggested to not use online compilers for such a thing and put it on my own webserver.然后@KIKO Software 建议不要将在线编译器用于此类事情,并将其放在我自己的网络服务器上。

I did so and found out the following error我这样做了,发现了以下错误https:// 包装器在服务器配置中被 allow_url_fopen=0 禁用

Then I just changed allow_url_fopen: to ON in PHP Manager (CPANEL) and everything just worked.然后我在 PHP 管理器 (CPANEL) 中将allow_url_fopen:更改为ON ,一切正常。

Thank you for the support!谢谢你的支持! Wish a lot of health to everybody祝大家身体健康

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM