簡體   English   中英

如何將同一職位的數據合並在一起?

[英]How to combine the data for the same post together?

我從2個網站上獲得了一些帖子數據,一個網站有標題,日期,描述和鏈接,而另一個網站有標題和圖像。

因此,如果兩個網站的標題相同,我想將圖像添加到其他帖子數據中。

這是我嘗試過的:

$articles = [];

//Getting Data From 1st Website
$rss = simplexml_load_file($website1);

foreach ($rss->channel->item as $item) {
    $post = []; 
    $post['title'] = (string)$item->title;
    $post['link'] = (string)$item->link;
    $post['date'] = (string)$item->pubDate;
    $post['description'] = (string)$item->description;

    $articles[$post['title']] = $post;
}

//Getting Data From The Second Website
require_once('simple_html_dom.php');
$html = file_get_html($website2);

    foreach($html->find($articlesClass) as $article) {
        $title    = trim($article->find($titlesClasse, 0)->plaintext);
        $img    = $article->find($imagesClass[$i], 0)->{'src'};     

        if ( isset ($articles[$title])){
            $articles[$title]['img'] = $img;
        }
        else    {
            $articles[$title] = ['title' => $title, 'img' => $img];
        }   
    }   

如何將其他日期(鏈接,日期和描述)添加到帶有標題和圖像的數組中?

改成:

if (in_array($title, $articles)){
    $articles[$title]['img'] = $img;
} else {
     //
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM