PHP回显工作,但preg#u match不';行不通
//我做了一些更改,但preg_match函数不起作用,echo也起作用。我不明白怎么了。我快疯了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
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);