Languages :: PHP :: Get filename |
|||
| By: kapot |
Date: 03/08/2003 00:00:00 |
Points: 50 | Status: Answered Quality : Excellent |
|
How can I parse the filename from a list that I got from ftp_rawlist() function? I got the list like this : -rw-r--r-- 1 504 505 4526946 Aug 3 18:30 Manual - Macromedia - Flash MX.pdf -rw-r--r-- 1 504 505 2163562 Aug 3 18:28 eBook - Flash MX Level 2.pdf And I want to create a function that can return ONLY the filename. I tried like this : function getName($item) { $matches = array(); eregi("[a-z]{3} +[0-9]{1,2} [ 0-9\:]{4,5} ([^( \\-\\>)]+)", $item, $matches); return $matches[1]; } But then it will fail if the filename contain space character. Anyone can help me with this ? Thanks. |
|||
| By: VGR | Date: 03/08/2003 17:30:00 | Type : Answer |
|
| this is (nearly) a fixed-length format, so a simple substr($thestring,$somepos) will do (it takes the rest of the string starting at position $somepos ) Personally, I would do a strpos(':',$thestring) to get the hour:minute position of the colon character, then increment by4 and take this value ie : function getName($item) { $matches = strpos(':',$item); $thestring=($matches===FALSE)?"invalid filename '$item'":substr($item,$matches+4); return $thestring; } |
|||
| By: wtgee | Date: 03/08/2003 17:59:00 | Type : Comment |
|
| VGR is right that you should exploit the fact that the time is always going to be a pattern matching XX:XX. |
|||
| By: waygood | Date: 04/08/2003 19:23:00 | Type : Comment |
|
| If you have to use raw to match other parameters to the filenames then VGR has a great solution, otherwise why not use ftp_nlist. In case you do need to split everything then this expression will give size, month, day, hour, minute, filename eregi("([0-9]+) ([a-z]{3}) ([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2})(.*)$", $str1, $matches); |
|||
| By: waygood | Date: 04/08/2003 19:24:00 | Type : Comment |
|
| oops pasted my test code - change $str1 to $item |
|||
| By: kapot | Date: 04/08/2003 19:29:00 | Type : Comment |
|
| Thanks, I use VGR solution with a little correction : $matches = strpos($item, ':'); :) |
|||
| By: kapot | Date: 04/08/2003 19:31:00 | Type : Comment |
|
| That function is part of NotFTP application <A HREF="http://www.wonko.com/notftp">http://www.wonko.com/notftp</a> A web based ftp client written in PHP. It has some bugs, and I am trying to fix it :) because the authore does not response ... It is simple and has cool looking interface AND FREE ! Well, I cant find any other free web based ftp client tought :( |
|||
| By: wtgee | Date: 05/08/2003 21:09:00 | Type : Comment |
|
| Good for you. Good luck with it. Cheers! |
|||
| By: VGR | Date: 05/08/2003 21:09:00 | Type : Comment |
|
| ooops :D this happens all the time to me, given the inconsistency of PHP functions' arguments order |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








