Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trimg string need file name

Status
Not open for further replies.

Kurt111780

Technical User
Nov 20, 2003
235
GB
Hello,

I need to trim a string and get the file name (everything after the last /)

file.txt
dir2/file.txt
dir3/dir4/file.txt

In all cases I need it to return file.txt with out any /.

I tried this but it still has the /.
Code:
$trimName = strrchr($fileName, "/");

then I tried this but it returns nothing if the / isn't there.
Code:
$trimName = substr(($t=strrchr($fileName,'/'))!==false?$t:'',1);

How can I do this? Thanks, Kurt

It's only easy when you know how.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top