我正在研究提供序列化产品阵列的API。我正在使用PHP。我想分离每个数组并使用数组元素在HTML中创建列表。我不知道如何从数组中获取每个元素来制作一个列表。你能帮帮我吗?
<?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->
?>
上面的代码会产生类似下面的内容
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 :(得分:0)
使用像foreach
foreach($data as $datum){
echo $datum['id'];
echo $datum['prefix'];
// or :
} ?>
<div id="id-<?=$datum['id']?>" >
<h1><?=$datum['title']?> </h1>
<!-- etc -->
</div>
答案 1 :(得分: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 }
?>