因为服务器证券file_get_contents()
被禁用,所以我尝试使用cURL进行此功能。
$url ='https://example.com' .
'/b/'.urlencode($this->user_ID).'/o/'.urlencode($this->ID);
$url=$url.'/h/'.urlencode($hash);
$number=rand(0, 10)/10 ."";
$url=$url.$number;
$html = file_get_contents($url);
preg_match('/<td valign="bottom" class="sum">(.*?)<\/td\>/', $html , $matches);
return $matches[0];
我现在拥有的是
$url ='https://example.com' .
'/b/'.urlencode($this->user_ID).'/o/'.urlencode($this->ID);
$number=rand(0, 10)/10 ."";
$url=$url.$number;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$matches = curl_exec($ch);
curl_close($ch);
$html = file_get_contents($url);
preg_match('/<td valign="bottom" class="sum">(.*?)<\/td\>/', $html , $matches);
return $matches[0];
它是这样的还是我完全错了?现在如何改变这一行 - $html = file_get_contents($url);
?
答案 0 :(得分:1)
你必须在卷曲后删除对file_get_contents
的调用,你已经收到卷曲请求的回复。
替换此
$matches = curl_exec($ch);
用这个
$html = curl_exec($ch);
然后对响应进行preg_match
// $html = file_get_contents($url); this line is not needed
preg_match('/<td valign="bottom" class="sum">(.*?)<\/td\>/', $html , $matches);
return $matches[0];
最后,检查$matches
和$matches[0]