Jump to content

how to get image file name from string in php


t_machine

Recommended Posts

Hi, I have links from a database that contains the image name and type. How can i strip the name and file type from the link.

 

Example:

$string = 'http://mysite.com/images/myimage.png';

 

How can I parse that string and get myimage.png

 

Note also that the file type is not always .png, it is also .jpg, .jpeg, .gif....

 

Thanks

simple job for substr

 

$file_extension = substr($filename , strrpos($filename , '.') +1);

 

would return jpg, gif won't keep the dot.

 

strrchr($filename, '.')

 

would return .jpg .gif  but it will keep the dot.

 

another function called basename

 

$filename = "C:\test\to\etc\theimagefile.jpg";

 

basename($filename);

 

would return "theimagefile.jpg"

 

$file = basename($filename, ".jpg");

 

would return "theimagefile"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.