Code: Select all
$string = ' blah blah blah ANYTHINGCANBEHEREhttps://www.google.com/test.jpgANYTHINGCANBEHERE https://www.google.com/test.php http://www.google.com/test.JPG ANYTHING<https://pbs.twimg.com/media/EjgPYArWoAAUgPO?format=jpg&name=900x900>http://www.google.com/test.gifhttp://www.google.com/dodacom?pic=gif&stuff=lalala httpS://www.google.com/whatever.png';
Code: Select all
$s = preg_match_all('/(https?)(:\/\/)(.[^< ]*?)(\.?|\?){1}(jpg|jpeg|gif|png|[a-z]=jpg|jpeg|gif|png){1}/ui', $string, $matches, PREG_SET_ORDER);
// then instead to use foreach (but i guess foreach is faster):
echo'<pre>';
$res = array_column($matches, 0);
$res = array_map('strtolower',$res);
print_r($res);
exit;
Code: Select all
Array
(
[0] => https://www.google.com/test.jpg
[1] => http://www.google.com/test.jpg
[2] => https://pbs.twimg.com/media/ejgpyarwoaaugpo?format=jpg
[3] => http://www.google.com/test.gif
[4] => http://www.google.com/dodacom?pic=gif
[5] => https://www.google.com/whatever.png
)