2012-10-16 7 views
0

// 일부 변경을했지만 preg_match 함수가 작동하지 않고 작동합니다. 나는 틀린 것을 이해할 수 없다. 나는 갈거야 미친PHP는 작동하지만 preg_match가 작동하지 않습니다.

public function crawl() 
{ 
    $html = $this->getPageHTMLContent($this->getDomain().$this->entryPagePath); 
    $categoryPageDom = $this->getHtmlDom($html); 

    echo $categoryPageDom->find('div#pagination a.gh', 1)->attr['href']; 

    preg_match("/\?p=(.*)&q/", $categoryPageDom->find('div#pagination a.gh', 1)->attr['href'], $machtes); 
    var_dump($machtes); 
} 


public function getPageHTMLContent($url){ 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $contents = curl_exec ($ch); 
    curl_close ($ch); 

    return $contents; 
} 
+0

이 줄을 제거하십시오. curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true); – GBD

답변

0

return 문은 없습니다 curl_download에서 값을 반환 시도 $ categoryPageDom-> 찾기 ('사업부 #의 페이지 매김 a.gh 에코 ', 1) -> attr ['href ']; 나는 브라우저에서 http://www.xxxx.de/xxxxxxxxxxxxxxx=iw&artikel=101&detail=mak과 같은 것을 얻는다. 그러나 소스 코드를 보면 다음과 같이 보입니다. http://www.xxxx.de/xxxxxxxxxxxxxxx=iw& * amp; * artikel = 101 & * amp; * detail = mak 문제는 amp; 나는 이것을 제거하기 위해 str_replace을 사용합니다. 컬이 매우 잘 작동합니다.

1

, 내가 할 때 문제가 URL에 관련이

+0

좋아, 내가하지 않았다 –

+0

고맙습니다. 하지만 여전히 preg_match에 문제가 있습니다. echo를 실행하는 동안 작동하지 않습니다. categoryPageDom = file_get_html ("http://www.spirituosenstore.de/catalogsearch/result/index/?p=2&q=e&x=0 &y=0"); echo $ categoryPageDom ("/ div? #pagination a.gh ', 1) -> attr ['href ']; preg_match ("/ \? p = (. *) & q/", $ categoryPageDom-> find ('div # 페이지 매김 a.gh ', 1) -> attr ['href '], $ machtes); var_dump ($ machtes); –

관련 문제