2014-02-26 64 views
0

我正在研究提供序列化產品數組的API。我使用PHP。我想分開每個數組,並使用數組的元素來創建HTML中的列表。我不知道如何從數組中獲取每個元素來創建一個列表。你會幫我嗎?PHP中的序列化數組分隔

<?php 
$url="http://www.seoclerks.com/api?type=inlinead&s=&aff=119253&by=&mp=&p=&c=0&ul=4&am=40&ins=0&g=0&sub=0&os=0&sp=0&oby=&oh=ASC&f=serialized"; 
$feed=file_get_contents($url); 
$data=unserialize($feed); 
print_r($data); 
echo $data-> 
?> 

以上代碼生成的東西O/P像下面

Array ([13] => Array ([id] => 504 [prefix] => will [title] => send you 372 highly spinned comments for Scrapebox [description] => Hey there Download my list of Scrapebox comments.They are highly spun and they are really nice. [positive_ratings] => 0 [negative_ratings] => 0 [service_url] => http://a.seoclerks.com/linkin/119253/Other/504/send-you-372-highly-spinned-comments-for-Scrapebox [order_url] => http://a.seoclerks.com/linkin/119253/order?id=504 [display_title] => send you 372 highly spinned comments for Scrapebox for $5 [price] => 5 [tags] => scrapebox comments list [days] => 1 [views] => 1320 [image] => https://www.seoclerks.com/pics/504-1.png [image_small] => https://www.seoclerks.com/pics/t2/504-1.png [image_med] => https://www.seoclerks.com/pics/t/504-1.png [subscription] => 0 [instant_download] => 1 [total_orders] => 0 [last_update] => 1322071772 [total_bookmarks] => 0 [combined_ratings] => 0 [guarantee] => 0 [on_sale] => 0 [staff_certified] => 0 [seller_username] => JaanPorkon [seller_userlevel] => 4 [seller_bio] => I'm a professional internet marketer, programmer and a designer. I have been doing it around 

回答

0

反序列化數據後。根據您的設計,您只需循環瀏覽並在HTML標籤中使用它。您可以從SEOClerks's API Page找到所有支持的密鑰列表

<?php 
$url="http://www.seoclerks.com/api?type=inlinead&s=&aff=119253&by=&mp=&p=&c=0&ul=4&am=40&ins=0&g=0&sub=0&os=0&sp=0&oby=&oh=ASC&f=serialized"; 
$feed=file_get_contents($url); 
$data=unserialize($feed); 
foreach($data as $item){ ?> 
     <div id="id-<?php echo $item['id'];?>" > 
     <h1><?php echo $item['title'];?></h1> 
     <p><?php echo $item['descripition']; ?></p> 
     </div> 
<?php } 
?> 
0

使用一個迭代像foreach

foreach($data as $datum){ 

echo $datum['id']; 
echo $datum['prefix']; 

// or : 

    } ?> 

<div id="id-<?=$datum['id']?>" > 
    <h1><?=$datum['title']?> </h1> 
<!-- etc --> 
</div>