0
 $pattern = "/(?i)\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))/";

 $str =  file_get_html($_GET['url'])->plaintext;

 if($num_found = preg_match_all($pattern, $str, $out)) {
    print_r($out[0]);
 }

 Output
 Array ([0] => https://ssl.gstatic.com/gb/images/b_8d5afc09.png [1] => https://ssl.gstatic.com/gb/images/b8_3615d64d.png [2])

So now I want to find if any of the following links contains some specific word let's say this 'b_8d5afc09' and then i want to take that link and display that link only.

So far i have tried out using 'in_array' but it never finds even if the link even exists, am i doing something wrong? Any suggestions appreciated!!

if (in_array("b_8d5afc09", $out[0]))
  {
  echo "found";
  }
  else
  {
  echo "nope";
  }

1 Answers1

1

The function in_array checks if the full needle is equal to one value of the array. Not only a part. You can work with strpos like this:

foreach( $out[0] as $value )  {
  if( strpos( $value, 'b_8d5afc09' ) !== false )  {
    echo "found in $value";
    break;
  }
}
Robin Gillitzer
  • 1,603
  • 1
  • 6
  • 17