PHP Invalid argument supplied for foreach()
<p>A free video script that I am using returns this error in my browser on line 57. </p>

<blockquote>
  <p>Warning: Invalid argument supplied for foreach() in /home/babyjen/public_html/<strong><em>*</em>**<em>*</em>**<em>*</em>**</strong>.com/video/upload/index.php on line 57</p>
</blockquote>

<p>The <code>//</code> in "<a href="http://img.youtube.com/vi/" rel="nofollow">http://img.youtube.com/vi/</a>" on line 65 of the code below may be the problem or part of the problem. I changed it to <code>"http:/" . "/img.youtube.com/vi/"</code> and a online code checker says its good but the script stops working after awhile.</p>

<p>I've contacted the programer but he no longer supports it. I've researched online by reading articles on php and chapters in php books, and I've watched many hours of php videos but I do not understand this problem.</p>

<p>Php online code checker says: </p>

<blockquote>
  <p>Parse error: syntax error, unexpected T_STRING in your code on line 65</p>
</blockquote>

<pre><code>&lt;?php
include "init.php";

// ################# Start recognize SEO Url data #############################

preg_match_all("|page([0-9]*).html|U", $seo_title, $out, PREG_PATTERN_ORDER);
$_GET['p'] = $out[1][0];

if (empty($_GET['p'])) {
  $_GET['p'] = 1;
}

// if ($_GET['p']&gt;0) {
//  $seo_title = array_pop($p_url);
// }

$_GET['q'] = $frontpage_keyword;

// ################# Start getting Youtube GData ##############################

$video_list = YT_ListByTag($_GET['q'], $_GET['p']);

// ################# Start parse xml attributes manually ######################

preg_match_all('/&lt;[^&gt;]+&gt;/s',$video_list[1],$tags);

$i=0;
foreach ($tags[0] as $k =&gt; $v) {

  $v = str_replace('"',"\'",$v);

  if (substr($v, 0, 12) == '&lt;yt:duration') {
    preg_match("/seconds='(.*)'/i", $v, $matches); 
    $video_list[0]['entry'][$i]['duration'] = $matches[1];  
  }

  if (substr($v, 0, 14) == '&lt;yt:statistics') {
    preg_match("/viewCount='(.*)'/i", $v, $matches);
    $video_list[0]['entry'][$i]['view_count'] = $matches[1];  
  }

  if (substr($v, 0, 10) == '&lt;gd:rating') {
    preg_match("/numRaters='(.*)' average/i", $v, $matches);
    $video_list[0]['entry'][$i]['rating_num_raters'] = $matches[1];  

    preg_match("/average='(.*)'/i", $v, $matches);
    $video_list[0]['entry'][$i]['rating_average'] = $matches[1];  
  }

  if (substr($v, 0, 7) == '&lt;/entry') {
    $i++;
  }
}

// ################# Start construct video data ###############################

foreach ($video_list[0]['entry'] as $k =&gt; $v)
 {
        $id_raw = explode('/', $video_list[0]['entry'][$k]['id']);    
 $video_list[0]['entry'][$k]['id'] = array_pop($id_raw);
 $video_list[0]['entry'][$k]['author'] = $video_list[0]['entry'][$k]['author'][0]['name'];
 $video_list[0]['entry'][$k]['description'] = $video_list[0]['entry'][$k]['media:group'][0]['media:description'];
 $video_list[0]['entry'][$k]['category'] = $video_list[0]['entry'][$k]['media:group'][0]['media:category'];
 $video_list[0]['entry'][$k]['thumbnail'][0] = "http:/" . "/img.youtube.com/vi/" . $video_list[0]['entry'][$k]['id'] . "/0.jpg";
 $video_list[0]['entry'][$k]['thumbnail'][1] = "http:/" . "/img.youtube.com/vi/" . $video_list[0]['entry'][$k]['id'] . "/1.jpg";
 $video_list[0]['entry'][$k]['thumbnail'][2] = "http:/" . "/img.youtube.com/vi/" . $video_list[0]['entry'][$k]['id'] . "/2.jpg";
 $video_list[0]['entry'][$k]['thumbnail'][3] = "http:/" . "/img.youtube.com/vi/" . $video_list[0]['entry'][$k]['id'] . "/3.jpg";


  $keywords_raw = explode(',',$video_list[0]['entry'][$k]['media:group'][0]['media:keywords']);

     $i = 0;
         foreach ($keywords_raw as $k2 =&gt; $v2)
         {

            $video_list[0]['entry'][$k]['keywords'][$i] = trim($v2);
             $i ++;
          }
     }

// ################# Start calculate pagination ###############################

if((($_GET['p']+1) * $config['list_per_page']) &lt; $video_list[0]['opensearch:totalresults']) {
  $next_page = $_GET['p'] + 1;
}
if($_GET['p']&gt;1) {
  $prev_page = $_GET['p'] - 1;
}

// ################# Start assign template variables ##########################

$tpl-&gt;assign('total',ceil($video_list[0]['opensearch:totalresults'] / $config['list_per_page']));
$tpl-&gt;assign('videos',$video_list[0]['entry']);
$tpl-&gt;assign('keyword',urldecode(stripslashes($_GET['q'])));
$tpl-&gt;assign('next_page',$next_page);
$tpl-&gt;assign('prev_page',$prev_page);
$tpl-&gt;assign('curr_page',$_GET['p']);
$tpl-&gt;display('front.html');
?&gt;
</code></pre>
