2012-09-23 66 views
1

我想使用simple_html_dom重命名從抓取網站獲得的文件的文件名。這裏是我的整個代碼:在複製文件時將文件名與文件名重命名

foreach($html->find('h3[class=gs_rt] a') as $link1){ 
    foreach($link1->parent()->parent()->parent()->find('div[class=gs_ggs gs_fl]') as $link2){ 
     $docLink = $link2->first_child(); 
     if(strtolower(substr($docLink->href, strrpos($docLink->href, '.'))) === '.pdf') { 
      $title = strip_tags($link1->plaintext); 
      $webLink = strip_tags($link1->href); 
      $pdfLink = strip_tags($docLink->href); 
      copy($pdfLink, $savePath . basename($pdfLink)); 
     } 
    } 
} 

我想在這行標題重命名文件名:

copy($pdfLink, $title)); 

不過。它不起作用,怎麼了?請幫我

回答

1

看起來你需要在$ link2之外創建一個對象,然後才能訪問它的屬性。

+0

你能舉個例子嗎?使用我的代碼,我得到了正確的'$ title'並修正了'$ pdfLink' – bruine