0

I have a php notice stating undefined offset:5 on line 18 (in this example).

1   <?php session_start();
2
3   require_once ('admin/config.inc.php');
4
5   $key = (empty($_GET['key'])) ? "" : $_GET['key'];
6   $v = (empty($_GET['v'])) ? "1" : $_GET['v'];
7
8   $result_Video = mysqli_query($db , "SELECT mv.video_link_1, mv.video_link_2,mv.sort FROM `mra_videos` AS mv INNER JOIN `mra_channels` AS mc ON mc.id = mv.channel_id WHERE (mc.code ='" . $key . "') AND (mv.sort = " . $v . ") LIMIT 1");
9
10  $rows_Video = mysqli_fetch_array($result_Video , MYSQLI_NUM);
11  $video_1 = get_youtube_id_from_url($rows_Video['video_link_1']);
12  $video_2 = get_youtube_id_from_url($rows_Video['video_link_2']);
13
14  function get_youtube_id_from_url($urls) {
15  if (stristr($urls, 'youtu.be/')) { preg_match('/(https|http):\/\/(.*?)\/([a-zA-Z0-9_]{11})/i', $urls, $final_ID);
16  return $final_ID[3];
17  } else { preg_match('/(https|http):\/\/(.*?)\/(embed\/|watch\?v=|(.*?)&v=|v\/|e\/|.+\/|watch.*v=|)([a-zA-Z0-9_]{11})/i', $urls, $IDD);
18  return $IDD[5];
19  }
20  }
21  ?>

What's causing it and how can I prevent this?

ekalostz
  • 1
  • 4
  • 2
    Either you didn't count the number of memory capture patterns properly or the string didn't yield and matches. – Ja͢ck Dec 10 '14 at 11:15
  • Your regular expression in the else preg_match don't give you the $IDD[5]. – Serpes Dec 10 '14 at 11:16

0 Answers0