My code should convert "defindex" from array_inv into "item_name" from array_schema:
我的代码应该将array_inv中的“defindex”转换为array_schema中的“item_name”:
<?php
$apikey = "X";
$steamid = $steamprofile['steamid'];
$url_inv = "http://api.steampowered.com/IEconItems_730/GetPlayerItems/v0001/?language=en?key=". $apikey . "&steamid=" . $steamid . "&format=json";
$url_schema = "http://git.optf2.com/schema-tracking/plain/Counter%20Strike%20Global%20Offensive%20Schema?h=counterstrikeglobaloffensive";
$array_inv_raw = file_get_contents($url_inv);
$array_schema_raw = file_get_contents($url_schema);
$array_inv = json_decode($array_inv_raw,true);
$array_schema = json_decode($array_schema_raw,true);
foreach($array_inv['result']['items'] as $item){
foreach($array_schema['result']['items'] as $schemaItem){
if($item['defindex'] == $schemaItem['defindex']){
echo $schemaItem['item_name'].'<br />';
break;
}
}
}
?>
But it's resulting in these errors:
但它导致了这些错误:
Warning: file_get_contents(http://api.steampowered.com/IEconItems_730/GetPlayerItems/v0001/?language=en?key=x&steamid=76561198037897388&format=json): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /home/kartm/public_html/scripts/inv.php on line 6
警告:file_get_contents(http://api.steampowered.com/IEconItems_730/GetPlayerItems/v0001/?language=en?key=x&steamid=76561198037897388&format=json):无法打开流:HTTP请求失败! HTTP / 1.1 403禁止在第6行的/home/kartm/public_html/scripts/inv.php中
Warning: Invalid argument supplied for foreach() in /home/kartm/public_html/scripts/inv.php on line 12
警告:在第12行的/home/kartm/public_html/scripts/inv.php中为foreach()提供的参数无效
The urls: array_inv array_schema
网址:array_inv array_schema
I can't find any mistakes. Can you tell me what's wrong with this code?
我找不到任何错误。你能告诉我这段代码有什么问题吗?
1 个解决方案
#1
These errors were caused by a typo in a url:
这些错误是由网址中的拼写引起的:
http://api.steampowered.com/IEconItems_730/GetPlayerItems/v0001/?language=en?key=x&steamid=76561198037897388&format=json
It should have been & key=x instead of ?key=x.
应该是&key = x而不是?key = x。
file_get_contents couldn't fetch the url, thus the foreach had an invalid, empty argument.
file_get_contents无法获取url,因此foreach有一个无效的空参数。
#1
These errors were caused by a typo in a url:
这些错误是由网址中的拼写引起的:
http://api.steampowered.com/IEconItems_730/GetPlayerItems/v0001/?language=en?key=x&steamid=76561198037897388&format=json
It should have been & key=x instead of ?key=x.
应该是&key = x而不是?key = x。
file_get_contents couldn't fetch the url, thus the foreach had an invalid, empty argument.
file_get_contents无法获取url,因此foreach有一个无效的空参数。