2012-10-16 50 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

當我提出這個問題是關係到URL回聲$ categoryPageDom->找到('DIV#分頁a.gh ',1) - > attr ['href'];我在瀏覽器上得到了這樣的http://www.xxxx.de/xxxxxxxxxxxxxxx=iw&artikel=101&detail=mak。但是,當我看到源代碼時,它看起來像這樣: * amp; * artikel = 101 & * amp; * detail = mak問題是amp;我已經使用str_replace刪除它。捲曲效果很好

1

嘗試返回從curl_download的值,所以沒有return聲明

+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 - > find('div#pagination a.gh',1) - > attr ['href']; preg_match(「/ \?p =(。*)&q /」,$ categoryPageDom-> find('分頁a.gh',1) - > attr ['href'],$ machtes); var_dump($ machtes); –