我的代码显示了播放器的蒸汽库存,代码:
<?php
function recursiveFind(array $array, $needle)
{
$iterator = new RecursiveArrayIterator($array);
$recursive = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
$aHitList = array();
foreach ($recursive as $key => $value) {
if ($key === $needle) {
array_push($aHitList, $value);
}
}
return $aHitList;
}
$id = $_GET["id"];
$link = file_get_contents('http://steamcommunity.com/id/'.$id.'/inventory/json/730/2');
$link = json_decode($link, true);
$name = recursiveFind($link, "market_hash_name");
$csv = implode('<br />', array_values($name));
echo '<b>Total: </b>';
echo count($name);
echo '<br />';
#echo '<a href="http://steamcommunity.com/market/listings/730/'.$csv.'" />';
echo $csv;
# echo '</a>';
?>
示例输出:
总计:9
Glock-18 |水元素(久经沙场)
P250 |超新星(崭新出厂)
AK-47(StatTrak™)| Elite Build(经过现场测试)
AWP |蠕虫之神(久经沙场)
M4A4 | Urban DDPAT(经过现场测试)
UMP-45 | Urban DDPAT(经过现场测试)
MAC-10 | Urban DDPAT(经过现场测试)
沙漠之鹰| Urban DDPAT(经过现场测试)
Tec-9 |城市DDPAT(经过现场测试)
我想在每个元素中添加一个href链接,该链接开始&#34; http://steamcommunity.com/market/listings/730/ 这里是每个JSON元素
我该怎么做?
答案 0 :(得分:0)
替换以下内容:
// ...
$name = recursiveFind($link, "market_hash_name");
foreach($item in $name){
echo $item;
echo '<a href="http://steamcommunity.com/market/listings/730/' . urlencode($item) . '" />';
echo "<br/>";
}
echo '<b>Total: </b>';
echo count($name);
echo '<br />';