Simple HTMLDom - 我很困惑

问题描述:

我想在我的“普通”主页上显示我在自己的云实例上共享的所有文件。Simple HTMLDom - 我很困惑

我owncloudserver的网址是:https://cloud.berndklaus.at/public.php?service=files&t=187e4767cb0421c7505cc3ceee450289

从那里我想显示文件名,大小和我Hompage的最后修改日期。我实际上能够显示文件名和最后修改的名称,但不显示文件大小。

我尝试了几个想法,但没有任何工作,你能帮我吗? 对不起,我的(坏)英语! :)

代码来显示:

   $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; 
        } 

     ?> 

这里的检索所需信息清洁的方式......我们的想法是获取所有的行,然后提取循环中的有用数据:

$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); 

输出

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

Working DEMO

+0

非常感谢你,你的男人!我只是将加载文件更改为:$ html = file_get_html($ url); – Berndinox