$gOutRecords = array(); if (strlen($gYTSearch) >= 3) { $lHTML = file_get_html(Config::$YoutubeSearchVideoURL . urlencode($gYTSearch)); $lVideo = new Videos(); foreach($lHTML->find('div[class=yt-lockup-content] h3 a') as $lElement) { if (strlen($lElement->href) > 0 && strlen($lElement->title) > 0) { if (!preg_match(Config::$YoutubeIgnoreResultRegex, $lElement->title)) { $lYTID = Youtube::extractYTID($lElement->href); $lYTTitle = preg_replace('/[\'\"\`\=\&\%\'\+]+/', ' ', $lElement->title); $lYTTitle = preg_replace('/\s{2,}/', ' ', $lYTTitle); if (Youtube::validYoutubeID($lYTID)) { $lRec = " {\n"; $lRec .= " \"ytid\": \"$lYTID\",\n"; $lRec .= " \"href\": \"$lElement->href\",\n"; $lRec .= " \"title\": \"$lElement->title\"\n"; $lRec .= " }"; array_push($gOutRecords, $lRec); $lVideo->addVideo($lYTID, $lYTTitle); }