RE: [PHP] Removing script name
| From: | Matthias Endler | Date: | Mon, 16 Oct 2000 20:25:54 +0000 |
| Subject: | RE: [PHP] Removing script name | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-20451@lists.php.net to get a copy of this message | ||
Hi Todd,
> If I have C:\MyDir\MyFile.txt, how can I remove the "MyFile.Txt" so that
> I have "C:\MyDir\" remaining. I have never mastered the pattern
> matching in Perl!!
you can do this in php in three diffrent ways:
<?
// This is the most efficient
$path = "C:\\MyDir\\MyFile.txt";
$file = substr($file,strrpos($file,"\\")+1,strlen($file));
print $file."<br>\n";
// Faster than ereg_*-function
preg_match("/.*\\\\([^\\\\]+)$/",$path,$file);
print $file[1]"<br>\n";
// Slowest
$file = ereg_replace(".*\\\\([^\\\\]+)$","\\1",$file);
print $file"<br>\n";
?>
Cheers,
Matthias aka Matthew