Re: Stripping filepath from string

From: Date: Tue, 09 Oct 2001 15:18:55 +0000
Subject: Re: Stripping filepath from string
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-9767@lists.php.net to get a copy of this message
this regex/example should do: <? $str = "/my/file/path/myfile.asd"; $filename = 'no match!'; if (preg_match("/[^\\\\\/]+$/", $str, $matches)) $filename = $matches[0]; echo $filename; ?> "Christian Sandfeld" <csa@zen-sys.com> wrote in message news:8710AE4FCD7ED511B1C800025558393005C92C@ZENSYS02... > Hi list, > > I know I have seen this somewhere - but I can't find it (and for some reason > I can't get my head around it). > > Is there a predefined function or alternatively an easy way to strip the > filepath of a string containing both filepath and filename? > > Strings could look like this: > /my/file/path/myfile > /my/file/path/myfile.name > c:\my\file\path\myfile > c:\my\file\path\myfile.name > etc... > > I know this should be fairly simple, but my mind is blank (if there's no > predefined function I know I should probably use some regex, but me and > regex don't get along (I always mess up)). > > Any help will be greatly appreciated :-) > > /Christian

« previous php.windows (#9767) next »