1

I have a URL in which the structure of the first part always changes and last part doesn't.

Using this url as input:

https://ig-s-b-a.akamaihd.net/hphotos-ak-xfa1/t51.2885-19/17438789_1884899458414605_8605163171642081280_a.jpg

I would like to capture:

/17438789_1884899458414605_8605163171642081280_a.jpg

Can I use preg_match() for this?

Other captured filenames would look like:

/17438789_1884899458414605_8605163171642081280_a.jpg
/17438789_111111111111_862222222222222642081280_a.jpg
/1741111111111789_1555555555605_812222222081280_a.jpg
mickmackusa
  • 43,625
  • 12
  • 83
  • 136
jack whacky
  • 53
  • 2
  • 5

1 Answers1

0

You dont need regex here. You can explode with / and get last item of array

$str=" https://ig-s-b-a.akamaihd.net/hphotos-ak-xfa1/t51.2885-19/17438789_1884899458414605_8605163171642081280_a.jpg";
$array=explode("/",$str);
echo end($array);
sumit
  • 15,003
  • 12
  • 69
  • 110