Jump to content

[SOLVED] How To Create A PHP Class that parses input.


btray77

Recommended Posts

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

 

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>";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.