Search code examples
phpimgur

Get the ID of an imgur image


Here are some examples of imgur links:

https://imgur.com/gallery/s2Bqq
https://i.imgur.com/26xcQUF.jpg
http://i.imgur.com/rfw7jrU.gif
http://i.imgur.com/rfw7jrU.gifv

The imgur API specifically asks for the ID of the image (s2Bqq, 26xcQUF, etc), but offers no way, from what I've seen, to get the ID of an image given a link.

So my question is, how would I, using PHP, get the ID of any imgur link?


Solution

  • Take the last component of the path and remove any extension on it.

    One approach:

    $id = pathinfo($url, PATHINFO_FILENAME);