[thelist] PHP string manipulation

Anthony Baratta Anthony at Baratta.com
Thu Jun 26 18:25:07 CDT 2003


At 04:13 PM 6/26/2003, Anthony Baratta wrote:
>At 03:58 PM 6/26/2003, Mark Joslyn wrote:
>>I am having the hardest time writing a string manipulation that will take
>>the following:
>>
>>Directory_One/Directory_Two/FileName1.zip
>>
>>or
>>
>>Directory_One/Filename1.zip
>>
>>(the paths can have from 1 to 3 directories separated by "/")
>>
>>I need everything left of the last "/" returned as a string including the
>>last "/" (essentially just removing the filename).

Here's a quick and dirty example:

$OldePath = "/dir1/dir2/dir3/dir4/file.name";
$aryPath = explode("/",$OldePath);
$foo = array_pop($aryPath);
$NewPath = implode("/",$aryPath) + "/";

Not fully tested, you get the idea.

-- 
Anthony Baratta
President
Keyboard Jockeys

"Conformity is the refuge of the unimaginative."



More information about the thelist mailing list