visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: Get filename


By: kapot U.S.A.  Date: 03/08/2003 00:00:00  English  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 English  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 English  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 English  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 English  Type : Comment
oops pasted my test code - change $str1 to $item
By: kapot Date: 04/08/2003 19:29:00 English  Type : Comment
Thanks, I use VGR solution with a little correction :

$matches = strpos($item, ':');

:)

By: kapot Date: 04/08/2003 19:31:00 English  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 English  Type : Comment
Good for you. Good luck with it. Cheers!
By: VGR Date: 05/08/2003 21:09:00 English  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

EContact
browser fav
page generated in 310.066940 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page