Capturing a particular link in an array

0

I need to check if there is and capture links that contain (youtube.com/embed) in an array. The position of the link in the array is always variable. How should I do it?

Array
(
    [0] => esqueci
    [1] => de
    [2] => entrar
    [3] => no
    [4] => link
    [5] => https://www.youtube.com/embed/zHNOQpl00_I
    [6] => para
    [7] => poder
    [8] => testar,
    [9] => https://www.google.com.br,
    [10] => https://terra.com.br,
    [11] => https://www.youtube.com/videos/asdasd
    [12] => 

)

Thank you in advance,

    
asked by anonymous 25.01.2018 / 13:41

1 answer

0

use for to traverse its array , and use the function strpos ()

for($i = 0; $i < $array.length; $i++){

  // valor é um item do array
  $findme   = 'youtube.com/embed';
  $pos = strpos($array[$i], $findme);

    if ($pos === false) {
     echo "A string '$findme' não foi encontrada no array '$array[$i]'";
    } else {
      echo "A string '$findme' foi encontrada na string '$array[$i]'";
      // aqui $array[$i] estara sua url.
      echo " e existe na posição $pos"; 
    }

}
    
25.01.2018 / 13:55