Get file extension in php

We often need to get the file extension of any file while working with php. We can get it in different ways. Here are some functions to get the file extension. Just pass the filename

  $file='myimage.jpg';

  (1) echo $ext1= end(explode('.',$file));

  (2) echo $ext2= array_pop(explode('.',$file));

  (3) echo $ext3= substr(strrchr($file,'.'),1);

  (4) $ext4=pathinfo($file);
      echo $ext4['extension'];


All above will give us file extension.
Get file extension in php Get file extension in php Reviewed by Altaf Hussain on 5:57 PM Rating: 5

1 comment:

Altaf Web. Powered by Blogger.