2015-07-04 56 views
1

的每個元素我有代碼,顯示的播放器,代碼蒸汽庫存:添加連結JSON

<?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
格洛克-18 |水元素(現場測試)
P250 |超新星(新產品)
StatTrak™AK-47 | Elite Build(實地測試)
AWP |蠕蟲神(經過實地測試)
M4A4 |城市DDPAT(實地測試)
UMP-45 |城市DDPAT(實地測試)
MAC-10 |城市DDPAT(實地測試)
沙漠之鷹|城市DDPAT(實地測試)
Tec-9 |城市DDPAT(現場測試)

而且我希望添加到其中的每個元素開始「http://steamcommunity.com/market/listings/730/這裏JSON

我該怎麼辦呢?

+0

編輯您的問題與答覆json – Viral

+0

@病毒json響應:http://pastebin.com/raw.php? i = cQdsmZXp – cal1fornia

+0

而不是使用'implode',使用for循環並在那裏添加鏈接。 – JCOC611

回答

0

的每個元素A HREF鏈接替換以下內容:

// ... 
$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 />';