btray77 Posted October 10, 2009 Share Posted October 10, 2009 I need some help on how to make a class that will parse out FTP MLSD command data (Look at $dirlist for what this data looks like). Below is an example of what I've got so far. I need to be able to easily page though the list and tell if it's a cdir, pdir, size, modified date, and file name. If someone could help me on this I would be grateful. The bad code I have so far: <?php $dirlist = array(); $dirlist[]='size=0;type=cdir;create=20070706174144;modify=20090928144627; .'; $dirlist[]='size=0;type=pdir;create=20070705203844;modify=20091008050005; ..'; $dirlist[]='size=252;type=file;create=20070706174144;modify=20090928144627; 10059-janitorial.zip'; $dirlist[]='size=1946215;type=file;create=20070706174152;modify=20090928144627; 10059-office.zip'; $dirlist[]='size=59658117;type=file;create=20070706174252;modify=20090928144622; 10059.txt'; $dirlist[]='size=6285651;type=file;create=20070706175413;modify=20090928144622; 10059.txt.gz'; $dirlist[]='size=6285853;type=file;create=20070706175529;modify=20090928144624; 10059.zip'; //print_r($dirlist); for($i = 0; $i < sizeof($dirlist); ++$i) { $temp = array(); $temp = explode(';',$dirlist[$i]); for($x = 0; $x < sizeof($temp); ++$x) { $td[$i][$x]=explode('=',$temp[$x]); } //$dirarray[$i] } echo "<PRE>"; //print_r($dirarray); print_r($td); echo "</PRE>"; ?> Thanks Link to comment https://forums.phpfreaks.com/topic/177162-solved-how-to-create-a-php-class-that-parses-input/ Share on other sites More sharing options...
Garethp Posted October 10, 2009 Share Posted October 10, 2009 Here, because I was bored <?php class Parsedata { function __construct($Link) { $Things = split(";", $Link); $this->Name = array_pop($Things); foreach($Things as $k=>$v) { $Temp = split("=", $v); $Name = $Temp[0]; $Val = $Temp[1]; $this->$Name = $Val; } } } $Test = new Parsedata ('size=6285651;type=file;create=20070706175413;modify=20090928144622; 10059.txt.gz'); echo "Size: " . $Test->size . "<br>"; echo "Type: " . $Test->type . "<br>"; echo "Create: " . $Test->create . "<br>"; echo "Modify: " . $Test->modify . "<br>"; echo "Name: " . $Test->Name . "<br>"; ?> Link to comment https://forums.phpfreaks.com/topic/177162-solved-how-to-create-a-php-class-that-parses-input/#findComment-934168 Share on other sites More sharing options...
btray77 Posted October 10, 2009 Author Share Posted October 10, 2009 THANK YOU! I appreciate the work! -Brad Link to comment https://forums.phpfreaks.com/topic/177162-solved-how-to-create-a-php-class-that-parses-input/#findComment-934530 Share on other sites More sharing options...
Garethp Posted October 10, 2009 Share Posted October 10, 2009 I was bored, it was no problem. Just remember to hit the "Topic Solved" button Link to comment https://forums.phpfreaks.com/topic/177162-solved-how-to-create-a-php-class-that-parses-input/#findComment-934591 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.