0

If I have abcxyz.doc for example and want to return the extension minus the dot, so just doc as a substring. I cannot rely on the extension always being 3 chars.

<?php
$x = 'abcxyz.doc';
ltrim(strrchr($x, '.'), '.');

Is this the best I can do, or is there a more elegant way to do this?

Marc
  • 746
  • 1
  • 12
  • 28
  • Since this has been shut down, I have to answer here please up-vote comment if useful echo $ext = pathinfo($x, PATHINFO_EXTENSION); – Demodave Jan 22 '15 at 14:26

1 Answers1

2

You can use $ext = pathinfo($filename, PATHINFO_EXTENSION) that already does that for you :)

sjagr
  • 15,983
  • 5
  • 40
  • 67
MoshMage
  • 506
  • 5
  • 30