2012-09-23 4 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

관련 문제