Regexp不使用cURL url内容

时间:2016-03-15 05:51:22

标签: php regex curl

在我的代码中,当我将Regexp内容分配给变量但不使用html时,我的url path工作正常。我得到空阵列。

    <?php 
    $productmfgno = "154637401";
                $url = "http://www.pandorasoem.com/search#q=".$productmfgno;
                $ch1= curl_init();
                curl_setopt ($ch1, CURLOPT_URL, $url );
                curl_setopt($ch1, CURLOPT_HEADER, 0);
                curl_setopt($ch1,CURLOPT_VERBOSE,1);
                curl_setopt($ch1, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)');
                curl_setopt ($ch1, CURLOPT_REFERER,'http://www.google.com');  //just a fake referer
                curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch1,CURLOPT_POST,0);
                curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, 20);
                $htmlContent= curl_exec($ch1);
                curl_close($ch1);
      /* It works when I assign this html content to $htmlContent variable but not working with cURL url

  $htmlContent = '<div class="findify-navigation-header findify-clearfix"> <div class="findify-pagination findify-push-right"></div> <div class="findify-header">Showing 2 results for <span class="findify-query">"154637401"</span>. <span id="findify-didyoumean"></span></div> </div>';

*/
                preg_match_all('/<div.*class=\"findify\-header\".*?>(.*?)<span.*class=\"findify-query\">.*?<\/div>/Us', $htmlContent, $count);
                print_r($count);

预期结果 - Showing 2 results for

所以我可以获取结果计数。