php - Get imgur ID from URL -


how id given imgur url. here examples of different types of urls:

https://imgur.com/gallery/arp2otg https://i.imgur.com/ycarzxr.jpg http://imgur.com/syukfyj 

as far know, length of ids vary.

a similar question asked here on se, it's not flawless.

for example, url https://imgur.com/syukfyj& not work answer given question. notice & appended end of url.

i think you're trying extract word chars @ start exists in last part.

preg_match('~/\k\w+(?=[^/]*$)~m', 'https://imgur.com/syukfyj', $id); echo $id[0]; 

demo

ideone


Comments