工作是PHP工程師今天寫程式時再用foreach $obj 時竟然卡住了...
還用要上網找資料
把$obj->id寫成 $obj['id'];
覺得實在練習不夠,想做一點array跟obj等資料整理或是迴圈的練習
但實在是不太想用資料庫(家裡電腦沒裝資料庫)
雖然知道laravel有假資料填充但laravel還不熟
希望資料可以是物件裡有陣列,或是陣列裡有物件
希望資料型態可以多一些(時間/HTML/圖片)
不知道有沒有能生成這樣資料的地方?
謝謝各位
話說寫個網頁爬蟲,就是把別人的網站當作是資料產生器,要多少有多少,對吧?
爬KKBOX
functiong getKKBOX($singer){
    $url = "https://www.kkbox.com/tw/tc/search.php?word={urlencode($singer)}&search=song&cur_page=";
    $res = array();
    for ($page = 1; $page <= 10; $page++) { // 一頁10行,取10頁
        $alltd = file_get_html($url.$page)->find("td[class=song-data]");
        if (count($alltd) > 0) {
            foreach ($alltd as $td) { // 抓到的頁面按td[class=song-data]一個個解開
                $vtd = str_get_html($td);
                $title = $vtd->find("a", 0)->innertext; // 歌手名字
                $vsg = $vtd->find("div[class=song-artist-album]", 0)->find("a", 0)->title; //歌名及相關資料
                $bname = trim($vsg) . " " . trim($title);
                $bname = preg_replace('/\s{2,}/', ' ', $bname); // 把過多的空白縮減成一個空白
                if (trim($bname) != "" and in_array($bname, $res) == false) {
                    array_push($res, $bname);
                }
            }
        } else {
            break;
        }
    }
    return $res ;
}
不想要用DB 但是要各種資料型態的假資料
你這需求我還真是不知道要怎麼滿足
給 SQL檔也不對
你是要別人組好一串你要的東西給你...練習...?