Willy Makend
Willy Makend

Reputation: 137

PHP echo work but preg_match doesn't work

// I have make some change but preg_match function doesn't work and echo Work. I can not understand what is wrong. I'm going crazy

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

Upvotes: 0

Views: 205

Answers (2)

Willy Makend
Willy Makend

Reputation: 137

The problem was related to URL When i make echo $categoryPageDom->find('div#pagination a.gh', 1)->attr['href']; I get something like this http://www.xxxx.de/xxxxxxxxxxxxxxx=iw&artikel=101&detail=mak on the Browser. But when I see the source code, it looks like this http://www.xxxx.de/xxxxxxxxxxxxxxx=iw&*amp;*artikel=101&*amp;*detail=mak The problem was amp; i have use str_replace to remove it. Curl works very well

Upvotes: 0

vvondra
vvondra

Reputation: 3162

Try returning a value from curl_download, there's no return statement

Upvotes: 1

Related Questions