[PHP] first output from for-loop?

by rtws
3 replies
Hi,

I'm trying to figure out how to display a VIDEOID from a class when a variable is empty.

in the HTML part <?=$service->view($tag)?> outputs 12 videos, but what i'm try to obtain is additionally the 1st VIDEOID as a preview at domain.com/keyword/


.htaccess
PHP Code:
RewriteEngine on
RewriteRule 
^([^/.]+)/$ index.php?tag=$1 [L]
RewriteRule ^([^/.]+)/results-([0-9]+)/$ index.php?tag=$1&page=$2 [L]
RewriteRule ^([^/.]+)/([^/.]+)$ index.php?tag=$1&video=$2 [L] 
index.php
PHP Code:
class Youtube
{var $dom, $idvideo, $title, $video, $VIDEOID;
function 
pagination()
{return 
true;}
function 
tag($tag, $page = 1) 
{if (
$page <= 0) $page = 1;
$start = ($page-1)*50 + 1;
$tag = str_replace(' ', '-', $tag);
$feed =   ('https://gdata.youtube.com/feeds/api/videos?vq='.$tag.'&orderby=relevance&start-index='.$start.'&max-results=12&orderby=relevance&alt=rss&key='.$APIKey.'');
$this->dom = getFeed($feed);} 
function 
view($tag){
$videos = $this->dom->getElementsByTagName('item');
foreach (
$videos as $video)
{
$id = $video->getElementsByTagName('guid')->item(0)->textContent;
$id = explode('/', $id); $VIDEOID = $id[6];
$title = $video->getElementsByTagName("title")->item(0)->textContent;
$tag2 = str_replace(' ', '-', $tag);
echo 
'<div class="'.ThumbnailClass.'"><a   href="/'.$tag.'/'.$VIDEOID.'"><div   class="'.ImageClass.'"><img   src="https://i.ytimg.com/vi/'.$VIDEOID.'/2.jpg" alt="'.$title.'"   width="180" height="135"   /></div><h2>'.$title.'</h2></a></div>';      
}
$service = new Youtube; 
$tag = isset($_GET['tag'])?htmlentities($_GET['tag']):$tag = str_replace(' ', '-', $keywords[0]);
$page = (isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] >= 0)?$_GET['page']:1;
$videos = $service->tag($tag, $page);
$video = isset($_GET['video'])?htmlentities($_GET['video']):$VIDEOID; 
Thanks for help
#forloop #output #php

Trending Topics