-1

I have string "katrina.bhuvnesh.jpg" , I want to get jpg that means substring that matches the last dot(.)

I looked in substr() function but it's not working exactly what I need.

Please give me any function of PHP that matches string from last and returns substring from that point.

Thanks!!

user2307273
  • 29
  • 2
  • 9

2 Answers2

5

Use pathinfo() like this:

 $extension = pathinfo("katrina.bhuvnesh.jpg", PATHINFO_EXTENSION);
Ja͢ck
  • 166,373
  • 34
  • 252
  • 304
1

You can use 2 function calls:

$filename = 'somefile.sometext.jpg';

$type = end(explode('.', $filename));

// $type is now 'jpg'

Alternatively, you can use substr:

$type = substr($filename, strrpos($filename, '.'));
Phil Cross
  • 8,619
  • 11
  • 45
  • 79