Simple HTMLDom - i'm confused

100 views Asked by At

I would like to show all files i share on my owncloud instance on my "normal" homepage.

The URL of my owncloudserver is: https://cloud.berndklaus.at/public.php?service=files&t=187e4767cb0421c7505cc3ceee450289

From there i would like to show the Filename, the Size and the Last modified Date on my Hompage. I'm actually able to display the Filename and the Last modified name but not the Filesize.

I tried several thinks, but nothing worked, could u help me out? Sorry for my (bad) english!! :)

Code to display:

                $html = file_get_html('https://cloud.berndklaus.at/public.php?service=files&t=187e4767cb0421c7505cc3ceee450289');
            //find the table
            $td = $html->find('td');  
                //find all links inside the table 

                foreach($td as $tds)
                    {
                    // Output the Links
                    //echo $tds;
                    echo $tds->find('a',0) . "-";
                    echo $tds->find('span[class=modified]', 0)->plaintext;
                    }

        ?>
1

There are 1 answers

1
Enissay On BEST ANSWER

Here's clean way to retrieve the wanted informations... The idea is to retrieve all rows then extract the useful data inside a loop :

$url = "https://cloud.berndklaus.at/public.php?service=files&t=187e4767cb0421c7505cc3ceee450289";

//Create a DOM object
$html = new simple_html_dom();
// Load HTML from a string
$html->load_file($url);

// Find all rows (files)
$files = $html->find('#fileList tr[data-id]');

// loop through all found files, extract and print the content
foreach($files as $file) {

    $fileName = $file->find('span.nametext', 0)->plaintext;
    $fileSize = $file->find('td.filesize', 0)->plaintext;
    $modDate = $file->find('span.modified', 0)->title;

    echo $fileName . " # " . $fileSize . " # " . $modDate . "<br>";
}

// Clear DOM object
$html->clear();
unset($html);

OUTPUT

Christi und Bernd - XMAS.JPG # 363.1 kB  # December 29, 2013 10:59

Working DEMO