2016-06-20 2 views
0

У меня есть эта функция, которую я пытаюсь сделать с помощью cURL из-за серверных ценных бумаг. file_get_contents() отключен.Rewrite file_get_content с помощью 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

Вы пробовали? это работает? Также, что случилось с '$ url. '/ H /'. Urlencode ($ hash);' вам он больше не нужен? –

+0

Я забыл '$ url. '/ H /'. Urlencode ($ hash);' он есть .. Когда я запускаю это с помощью curr try, я получил ошибку 'file_get_content(): https: // wrapper отключен на этом сервере' в этой строке '$ html = file_get_contents ($ url);' –

+0

вы сказали, что хотите использовать завиток, почему вы используете код 'file_get_contents'? –

ответ

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]

+0

Спасибо, это так очевидно ... –