-3

我正在为 pinterest http://www.zacharydavidbiles.com/2012/05/scraping-pinterest-with-php/实现 af 抓取脚本- 到目前为止一切顺利,我已经成功运行它,但我缺乏足够的 php了解如何将数组解析为有用的 html。

<?php
    include_once('wp-content/themes/symbol/inc/Pinterest.class.php');
    $pinterest = new Pinterest();
    $pinterest->scrapeUser("casperovergaard");
    $pinterestCovers = $pinterest->getCovers();
    $pinterestThumbs = $pinterest->getThumbs();
    $pinterestLinks = $pinterest->getLinks();

        print_r($pinterestThumbs);
?>

结果是我的 pinterest 中的一长串网址

Array ( 
    [0] => http://media-cache-lt0.pinterest.com/upload/6544361930035694_2fOhWLC4_t.jpg 
    [1] => http://media-cache-ec6.pinterest.com/upload/6544361930030994_baSRTSh6_t.jpg 
    [2] => http://media-cache-ec5.pinterest.com/upload/6544361929998833_uKTPTrRX_t.jpg 
    [3] => http://media-cache-ec4.pinterest.com/upload/6544361929912044_R8TrDlRF_t.jpg 
) 
    [1] => Array ( 
            [0] => http://media-cache-lt0.pinterest.com/upload/6544361930051890_Mjzguspo_t.jpg 
            [1] => http://media-cache-ec2.pinterest.com/upload/106116134940631272_QWvrC09l_t.jpg 
            [2] => http://media-cache-ec6.pinterest.com/upload/92323861080593762_sQGFb6Cw_t.jpg 
            [3] => http://media-cache-ec6.pinterest.com/upload/50806302017302433_3PrHkE8A_t.jpg 
    ) 
    [2] => Array ( 
            [0] => http://media-cache0.pinterest.com/upload/264234703107207356_JWq16vyi_t.jpg 
            [1] => http://media-cache-lt0.pinterest.com/upload/212513676136740135_Xh65hY5R_t.jpg 
            [2] => http://media-cache-ec3.pinterest.com/upload/18225573461849873_hEke4BiA_t.jpg 
            [3] => http://media-cache0.pinterest.com/upload/6544361929985568_HdGFAIaw_t.jpg 
    ) 
    [3] =>

所以我的问题是:如何将这个数组解析成可爱的图像?我一直在寻找,但徒劳无功。

4

3 回答 3

1

尝试这个:

foreach($pinterestThumbs as $img){
echo "<img src='$img' alt="" title=""/>";
}
于 2012-10-26T08:41:38.457 回答
1

像:

foreach ($pinterestThumbs as $thumb)
   echo "<img src='$thumb' alt='' >";

注意 alt 属性是 html 规范所要求的,所以不要省略它。

于 2012-10-26T08:43:32.353 回答
1

最简单的方法是

foreach ( $pinterestThumbs as $url ) { echo "<img src='{$url}'/>" }

于 2012-10-26T08:43:34.630 回答