Pattern matching in PHP?

  • Thread starter Thread starter Chab
  • Start date Start date
C

Chab

Guest
Suppose I have a variable $var="this.is.a.sample.file.name.txt" .
I'd like to get the 3 characters after the last "." (In other words the extension of a file), in this case i need a $ext="txt".
Could you give me the correct pattern or formula and how to code it?
Thanks
The problem with cutting the 3 characters from the end of the file with substr is that I don't know how long the extension of the file is (eg.: .h or .torrent are not handled correctly )
 
Back
Top