Alternate function for pathinfo() to get file extension?

I am creating a logic hook where I need to get the file extension. I have used pathinfo() to achieve the same. But when I tried to install on my 'OnDemand' instance, it resulted error saying can not use function pathinfo().
I checked this thread - Invalid usage of a reserved method name unlink() Sugar7  but the link mentioned is not found on GitHub.

Appreciate if anyone can help.

Thanks,

Shantanu

  • For pathinfo() you pass in a string.  Just treat it as such and use what you know about filenames. the extension is ALWAYS at the end and always has a period before it.  Explode the string by periods and take the last element of the array.   

    $path = "/this/is/my/file/path.php";
    $pathArray = explode('.', $path);
    $extension = end($pathArray);