如何用PHP判斷 迴圈div裡的 id 值是否為空白,如果不是空則正常顯示這個div層,如果為空白則隱藏?
下面的代碼是My Code。
不知道用PHP來判斷效率高還是用JQ判斷效率高。
//To try without API key: $video_list = json_decode(file_get_contents(''));$video_list = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId='.$channelId.'&maxResults='.$maxResults.'&key='.$API_key.''));foreach($video_list->items as $item) { //Embed video if(isset($item->id->videoId)){ echo 'id->videoId .'" class="xl12 xs6 xm4 xb3 video-box"> id->videoId .'" target="_blank" title="'. $item->snippet->title .'">id->videoId .'" class="radius img-responsive" alt="'. $item->snippet->title .'"> id->videoId .'">'. $item->snippet->title .'
'; } //Embed playlist else if(isset($item->id->playlistId)) { echo 'id->videoId .'" class="xl12 xs6 xm4 xb3 video-box"> id->videoId .'" target="_blank" title="'. $item->snippet->title .'">id->videoId .'" class="radius img-responsive" alt="'. $item->snippet->title .'"> id->videoId .'">'. $item->snippet->title .'
'; }}
下面這段代碼是視頻列表的父div,id="這裡擷取視頻的key ID號,"
id->videoId .'" class="xl12 xs6 xm4 xb3 video-box">
id->videoId .'" class="xl12 xs6 xm4 xb3 video-box">
//內部Html
因為是移步採集國外網站的視頻,所以有時候擷取不到視頻的key ID,所以就無法載入。
怎麼修改上面的代碼實現,判斷id->videoId .'"
這裡面的 id="值" 是否為空白,如果為空白則用 style或者class 的 display:none屬性隱藏這條空的視頻資訊?
回複內容:
如何用PHP判斷 迴圈div裡的 id 值是否為空白,如果不是空則正常顯示這個div層,如果為空白則隱藏?
下面的代碼是My Code。
不知道用PHP來判斷效率高還是用JQ判斷效率高。
//To try without API key: $video_list = json_decode(file_get_contents(''));$video_list = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId='.$channelId.'&maxResults='.$maxResults.'&key='.$API_key.''));foreach($video_list->items as $item) { //Embed video if(isset($item->id->videoId)){ echo 'id->videoId .'" class="xl12 xs6 xm4 xb3 video-box"> id->videoId .'" target="_blank" title="'. $item->snippet->title .'">id->videoId .'" class="radius img-responsive" alt="'. $item->snippet->title .'"> id->videoId .'">'. $item->snippet->title .'
'; } //Embed playlist else if(isset($item->id->playlistId)) { echo 'id->videoId .'" class="xl12 xs6 xm4 xb3 video-box"> id->videoId .'" target="_blank" title="'. $item->snippet->title .'">id->videoId .'" class="radius img-responsive" alt="'. $item->snippet->title .'"> id->videoId .'">'. $item->snippet->title .'
'; }}
下面這段代碼是視頻列表的父div,id="這裡擷取視頻的key ID號,"
id->videoId .'" class="xl12 xs6 xm4 xb3 video-box">
id->videoId .'" class="xl12 xs6 xm4 xb3 video-box">
//內部Html
因為是移步採集國外網站的視頻,所以有時候擷取不到視頻的key ID,所以就無法載入。
怎麼修改上面的代碼實現,判斷id->videoId .'"
這裡面的 id="值" 是否為空白,如果為空白則用 style或者class 的 display:none屬性隱藏這條空的視頻資訊?
直接用CSS
DIV[id=""] { display: none; }
WEB -> JS . SERVER -> PHP.
這個API獲得json。難道資料不完整嗎? 其中會有資料的id為空白?好奇怪吧。