Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP回显工作,但preg#u match不';行不通_Php_Curl - Fatal编程技术网

PHP回显工作,但preg#u match不';行不通

PHP回显工作,但preg#u match不';行不通,php,curl,Php,Curl,//我做了一些更改,但preg_match函数不起作用,echo也起作用。我不明白怎么了。我快疯了 public function crawl() { $html = $this->getPageHTMLContent($this->getDomain().$this->entryPagePath); $categoryPageDom = $this->getHtmlDom($html); echo $categoryPageDom->f

//我做了一些更改,但preg_match函数不起作用,echo也起作用。我不明白怎么了。我快疯了

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

尝试从curl#u下载返回一个值,没有
return
语句

当我执行echo$categoryPageDom->find('div#pagination a.gh',1)->attr['href']时,问题与URL有关;我在浏览器上看到类似的东西。但是当我看到源代码时,它看起来像这样*artikel=101&*amp*detail=mak问题是amp我已使用str_replace将其删除。Curl工作得很好

删除这条线Curl\u setopt($ch,CURLOPT\u FOLLOWLOCATION,true);谢谢,我可以调整一下。但是我仍然有一个preg#u match的问题,它在运行echo$categoryPageDom=file_get_html(“);echo$categoryPageDom->find('div#pagination a.gh',1)->attr['href'];preg#u match(“/\?p=(.*)&q/”,$categoryPageDom->find('div pagination a.gh',1)->attr['href',machtes];var#u dump($machtes);