balkan7 Posted January 20, 2009 Share Posted January 20, 2009 i need help to fix this errors: Notice: Undefined offset: 0 in C:\xampp\htdocs\cool\video\includes.php on line 116 Notice: Undefined offset: 0 in C:\xampp\htdocs\cool\video\includes.php on line 123 Notice: Undefined offset: 0 in C:\xampp\htdocs\cool\video\includes.php on line 127 to include file i get errors mostly in code -> $video = $Videos[$i]; so includes.php is: <?php /*======================================================================*\ || VideoGalerija v1.01 || || -------------------------------------------------------------------- || || Copyright 2008. All rights reserved. || \*======================================================================*/ //include("utils.php"); #DEBUG /*define(BROWSE_VID, 1); define(BROWSE_IMG, 3); define(BROWSE_TITLE, ; define(BROWSE_RUNTIME, 10); define(BROWSE_POSTDATE, 13); define(BROWSE_USERNAME, 15); define(BROWSE_VIEWS, 17); define(BROWSE_STAR1, 19); define(BROWSE_STAR2, 21); define(BROWSE_STAR3, 23); define(BROWSE_STAR4, 25); define(BROWSE_STAR5, 27); define(BROWSE_RATINGS, 29); define(SEARCH_VID, 1); define(SEARCH_IMG, 3); define(SEARCH_TITLE, 7); define(SEARCH_DESC, 11);*/ function getVEntries($pageText){ //preg_match_all('|\<div class=\"vEntry\">(.*?)\<\/div/> \<\!-- end vEntry --\>|',$pageText,$ventries); //preg_match_all('|\<div class\=\"vEntry\"\>(.*)\<\/div\> \<\!-- end vEntry --\>|',$pageText,$ventries); print $pageText; preg_match_all('|\<div class=\"v120vEntry\"\>(.*?)\<\/div\> \<\!-- end vEntry --\>|s',$pageText,$ventries); //print_r($ventries[1]); } CLASS YouTube { var $_Results; var $_ResultCount; function Browse($select = "mp", $time = "t", $category = "0" , $page = "1") { $results = file("http://www.youtube.com/browse?s=".$select."&t=".$time."&c=".$category."&l=&p=".$page); $results = implode("", $results); preg_match_all('|\<div class=\"v120vEntry\"\>(.*?)\<\/div\> \<\!-- end vEntry --\>|s',$results,$ventries); $this->videos=array(); foreach ($ventries[1] as $ventryText){ $this->videos[]=new vEntry($ventryText); } /* if ($select == "mr") { preg_match_all('/\<a href=\"\/watch\?v=(.*?)\" (.*?)\>\<img src=\"(.*?)\" class=\" vimg \" alt=\"(.*?)\" \/\>\<\/a\>(.*?)<div class="vtitle">(.*?)\<a href=\"\/watch\?v=(.*?)\"\>(.*?)\<\/a\>\<br\/\>(.*?)\<span class=\"runtime\"\>(.*?)\<\/span\>(.*?)\<div class=\"vfacets\"\>(.*?)\<span class=\"grayText\"\>Added:\<\/span\> \<script type=\"text\/javascript\"\>document.write\(format_time_ago\((.*?)\)(.*?)href=\"\/user\/(.*?)\"\>(.*?)Views:\<\/span\> (.*?)\<br\/\>/s', $results, $matches); } else { preg_match_all('/\<a href=\"\/watch\?v=(.*?)\" (.*?)\>\<img src=/', $results, $matches); } $this->_Results = $matches; //preg_match_all('/\<div class=\"headerTitleRight\"\> Videos (.*?)-(.*?) of (.*?)\<\/div\>/', $results, $matches); $this->_ResultCount = $matches[3][0];*/ } function Search($query, $page='1', $type='search_videos', $sort='relevance', $category = "0") { $query=urlencode($query); $url = "http://www.youtube.com/results?search_query=".$query."&page=".$page; if ($category) { $url .= "&search_category=".$category; } if ($sort) { $url .= "&search_sort=".$sort; } if ($type) { $url .= "&search_type=".$type; } $results = file($url); $results = implode("", $results); //print($results); preg_match_all('|\<div class=\"vEntry\"\>(.*?)\<\/div\> \<\!-- end vEntry --\>|s',$results,$ventries); $this->videos=array(); foreach ($ventries[1] as $ventryText){ $this->videos[]=new searchvEntry($ventryText); } /* preg_match_all('/\<a href=\"\/watch\?v=(.*?)\" name=\"(.*?)\"\>\<img src=\"(.*?)\" class=\"vimg120\" \/\>\<\/a\>(.*?)<div class="vtitle">(.*?)\<a href=\"\/watch\?v=(.*?)\"\>(.*?)\<\/a\>\<br\/\>(.*?)\<div class=\"vdesc\"\>(.*?)\<span id=\"(.*?)\"\>(.*?)\<\/span\>/s', $results, $matches); $this->_Results = $matches; preg_match_all('/\<div class=\"headerTitleRight\"\>(.*?)\<b\>(.*?)\<\/b\>-\<b\>(.*?)\<\/b\> of \<b\>(.*?)\<\/b\>/s', $results, $matches); $this->_ResultCount = $matches[4][0];*/ } function ResultCount() { return $this->_ResultCount; } function Results() { //no longer used return $this->_Results; } function Videos() { //print_r($this->videos); return $this->videos; } //nastiness brought in from search.php function GetSearchResults($search_query, $page) { return $this->Search($search_query,$page); /* $search_query = str_replace(" ", "+", $search_query); $results = file("http://youtube.com/results?search_type=search_videos&search_query=".$search_query."&search_sort=&search_category=0&page=".$page); $results = implode("", $results); preg_match_all('|\<div class=\"v120vEntry\"\>(.*?)\<\/div\> \<\!-- end vEntry --\>|s',$results,$ventries); $this->videos=array(); foreach ($ventries[1] as $ventryText){ $this->videos[]=new vEntry($ventryText);*/ } /* preg_match_all('/\<a href=\"\/watch\?v=(.*?)\" (.*?)\>\<img src=\"(.*?)\" border=\"0\" class=\"vimg120\" \/\>\<\/a\>(.*?)<div class="vtitle">(.*?)\<a href=\"\/watch\?v=(.*?)\"\>(.*?)\<\/a\>\<br\/\>(.*?)\<div class=\"vdesc\"\>(.*?)\<span id=\"(.*?)\"\>(.*?)\<\/span\>/s', $results, $matches); $this->_Results = $matches; preg_match_all('/\<div (.*?)\>Results (.*?)-(.*?) of (.*?)\<\/div\>/s', $results, $matches); $this->_ResultCount = $matches[4][0];*/ //} } function displayVideos($Videos){ $columns = "4"; $rows = "5"; $vpp = $columns * $rows; echo '<table align="center" width="750" border="0" cellspacing="5" cellpadding="5" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;">'; $i = 0; $video = $Videos[$i]; /* print "<hr><br/><b>Text</b>".$video->text; print "<br/><b>URL</b>".$video->video; print "<br/><b>Image</b>".$video->image; print "<br/><b>Title</b>".$video->title; */ for($r=0; $r<$rows; $r++) { $video=$Videos[$i]; echo '<tr>'; for($c=0; $c<$columns; $c++) { echo '<td valign="top" width="130">'; if($Videos[$i]){ $video=$Videos[$i]; if (isset($_GET['s']) and $_GET['s'] == "mr") { echo '<a href="pogledni.php?video='.$video->url.'"><img src="'.$video->image.'" border="0" width="130" height="97" /><br />'.$video->title.'</a><br />'.$locale['YT022'].' <script type="text/javascript">document.write(format_time_ago('.$video->postdate.'));</script><br />'.$locale['YT023'].' '.$video->views; } else { echo '<a href="pogledni.php?video='.$video->url.'"><img src="'.$video->image.'" border="0" width="130" height="97" /><br />'.$video->title.'</a><br />'.$locale['YT022'].' <script type="text/javascript">document.write(format_time_ago('.$video->postdate.'));</script><br />'.$locale['YT023'].' '.$video->views.'<br /><img src="http://youtube.com'.$video->star1.'" /><img src="http://youtube.com'.$video->star2.'" /><img src="http://youtube.com'.$video->star3.'" /><img src="http://youtube.com'.$video->star4.'" /><img src="http://youtube.com'.$video->star5.'" /><br />'.$locale['YT024'].' '.$video->ratings; } } echo '</td>'; $i++; } } echo '</table><div align="right" style="padding-right: 25px">'; } class searchvEntry{ //yes, this should probably be extending vEntry. maybe later //For now, the only differences are the regexps for the url and the function __construct($text){ $this->text=$text; preg_match('|<div class="vSnippetTitle">(.*?)\<a href=\"\/watch\?v=(.*?)\"\>(.*?)\<\/a\>|s',$this->text,$titles); $this->title=$titles[3]; preg_match('|\<a href=\"\/watch\?v=(.*?)\"|',$this->text,$vid); $this->url=$vid[1]; //better new name preg_match('|img src=\"(.*?)\" border=\"0\" class=\"vimg120\"|s',$this->text,$images); $this->image=$images[1]; preg_match('|\<span class=\"runtime\"\>(.*?)\<\/span\>|',$this->text,$runtimes); $this->runtime=$runtimes[1]; preg_match('|\<span class=\"runtime\"\>(.*?)\<\/span\>|',$this->text,$postdates); $this->postdate=$postdates[1]; preg_match_all('|\<img class=\"rating\" src=\"(.*?)\"|',$this->text,$stars,PREG_SET_ORDER); $this->views=''; $this->star1=$stars[0][1]; $this->star2=$stars[1][1]; $this->star3=$stars[2][1]; $this->star4=$stars[3][1]; $this->star5=$stars[4][1]; } } class vEntry{ function vEntry($text){ $this->text=$text; //preg_match('|div class=\"vtitle\"\>(.*?)\)\;\"\>(.*?)\<\/a\>\<\br\/\>|',$this->text,$titles); preg_match('|<div class="vtitle">(.*?)\<a href=\"\/watch\?v=(.*?)\"\>(.*?)\<\/a\>|s',$this->text,$titles); $this->title=$titles[3]; preg_match('|\<a href=\"\/watch\?v=(.*?)\"|',$this->text,$vid); $this->video=$vid[1]; //silly old name $this->url=$vid[1]; //better new name preg_match('|<img src=\"(.*?)\" class=\" vimg \"|',$this->text,$images); $this->image=$images[1]; preg_match('|\<span class=\"runtime\"\>(.*?)\<\/span\>|',$this->text,$runtimes); $this->runtime=$runtimes[1]; preg_match('|\<span class=\"runtime\"\>(.*?)\<\/span\>|',$this->text,$postdates); $this->postdate=$postdates[1]; preg_match_all('|\<img class=\"rating\" src=\"(.*?)\"|',$this->text,$stars,PREG_SET_ORDER); $this->views=''; $this->star1=$stars[0][1]; $this->star2=$stars[1][1]; $this->star3=$stars[2][1]; $this->star4=$stars[3][1]; $this->star5=$stars[4][1]; } /* here's the text we're matching <div class="v120vEntry"> <div id="QLContainer"> <div id="QLIcon"><a href="#" onClick="clicked_add_icon('8bbTtPL1jRs', 0);_hbLink('QuickList+AddTo','VidVert');return false;" title="Add Video to QuickList"><img id="add_button_8bbTtPL1jRs" border="0" onMouseover="mouse_over_add_icon('8bbTtPL1jRs');return false;" onMouseout="mouse_out_add_icon('8bbTtPL1jRs');return false;" src="/img/icn_add_20x20.gif" alt="Add Video to QuickList"></a></div> <div><a href="/watch?v=8bbTtPL1jRs"><img src="http://sjl-static7.sjl.youtube.com/vi/8bbTtPL1jRs/2.jpg" class=" vimg " alt="video" /></a></div> </div> <div class="vtitle"> <a href="/watch?v=8bbTtPL1jRs" onclick="_hbLink('MyChemicalRomanceFamousLastWords','VidVert');">My Chemical Romance - Famous Last Words</a><br/> <span class="runtime">04:27</span> </div> <div class="vfacets"> <span class="grayText">Added:</span> 3 months ago<br/> <span class="grayText">From:</span> <a href="/user/mYcheMicALroMaNcE">mYcheMicALroMaNcE</a><br/> <span class="grayText">Views:</span> 24657206<br/> </div> <img class="rating" src="/img/icn_star_full_11x11.gif" align="top"><img class="rating" src="/img/icn_star_full_11x11.gif" align="top"><img class="rating" src="/img/icn_star_full_11x11.gif" align="top"><img class="rating" src="/img/icn_star_full_11x11.gif" align="top"><img class="rating" src="/img/icn_star_half_11x11.gif" align="top"> <div class="rating ratingCount">20924 ratings</div> </div> <!-- end vEntry --> */ } ?> index.php <?php echo '<script type="text/javascript" src="http://youtube.com/js/browsePageTimeAgo_yts1157352107.js"></script>'; include("includes.php"); $yt = new YouTube; if (!isset($_GET['strana'])) { $Pages = 1; } else { $Pages = $_GET['strana']; } //$Search = $_GET[search]; if (!isset($_GET['s'])) { $Select = "mp"; } else { $Select = $_GET['s']; } //$yt->Search($Select,$_GET[t],$_GET[c],$Pages); $yt->Browse($Select,isset($_GET['t']),isset($_GET['c']),$Pages); //$TotalPages = $yt->ResultCount() / $vpp; if (isset($_GET['s']) and $_GET['s'] == "mr") { $TotalPages = 15; } else { $TotalPages = 5; } $Results = $yt->Results(); $Videos = $yt->Videos(); //print_r($Videos); displayVideos($Videos); $param = ""; foreach($_GET as $key => $value) { if (isset($key) and $key != 'strana') { if ($param != NULL) { $param .= "&"; } $param .= $key."=".$value; } }?> Quote Link to comment https://forums.phpfreaks.com/topic/141621-youtube-class-error/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.