如何用PHP判斷div 中的id值是否為空白

來源:互聯網
上載者:User
  1. 如何用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屬性隱藏這條空的視頻資訊?

回複內容:

  1. 如何用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為空白?好奇怪吧。

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.