2017-12-21 4 views
0

을 반환 :file_get_contents은 빈 문자열

<?php 
$html = file_get_contents('https://www.eltenedor.es/'); 

$albergina_doc = new DOMDocument(); 

libxml_use_internal_errors(TRUE); 
if(!empty($html)){ 
    $albergina_doc->loadHTML($html); 
    libxml_clear_errors(); 

    $albergina_xpath = new DOMXPath($albergina_doc); 
    $customer = array(); 
    $review = array(); 
    $albergina_array = array(); 
    $albergina_review = $albergina_xpath->query('//div[@class="reviewItem-customerComment"]'); //scrapping basico 
    $albergina_customer = $albergina_xpath->query('//div[@class="reviewItem-profileInfo"]'); //scrapping basico 

foreach ($albergina_customer as $row) { 
    $content = explode(' ', $row->nodeValue); 
    $customer_name = $content[40]." ".$content[41]; 
    array_push($customer,$customer_name); 

} 

foreach ($albergina_review as $row) { 
    array_push($review,$row->nodeValue); 
} 

for($i = 0; $i<count($customer); $i++){ 
    array_push($albergina_array, array('customer' => $customer[$i] , 'review' => $review[$i])); 
} 


echo (json_encode($albergina_array)); 


} 

내 로컬 서버에서 $의 HTML에 얻는 결과는 긍정적이다. 그러나, 그것을 내 FTP로 업로드하고 실행할 때 $ html의 내용은 비어 있으며 오류가 발생하지 않습니다. 누가 문제가 될 수 있는지 아는 사람이 있습니까?

+0

차례 서버에보고하고 경고를 얻을 수 있는지 확인합니다. – Vivek

답변

2

오류 로그를 확인하십시오. file_get_contents을 https URL로 사용하면 누락 된 래퍼와 같은 오류가 발생할 수 있습니다.

How to get file_get_contents() to work with HTTPS? 등록 된 래퍼를 확인하기 위해 다음과 같은 코드가 포함되어 오류에

$w = stream_get_wrappers(); 
echo 'openssl: ', extension_loaded ('openssl') ? 'yes':'no', "\n"; 
echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n"; 
echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n"; 
echo 'wrappers: ', var_export($w); 
+0

그 결과는 다음과 같습니다 : openssl : yes http 래퍼 : 예 https 래퍼 : 예 래퍼 : 배열 (0 => 'https', 1 => 'ftps', 2 => 'compress.zlib' , 3 => 'php', 4 => '파일', 5 => 'glob', 6 => '데이터', 7 => 'http', 8 => 'ftp', 9 => 'compress.bzip2 ', 10 =>'phar ', 11 =>'zip ') 래퍼가 켜져 있어야 작동합니다. –

+0

그래, 이상 하네. 오류 로그에 내용이 있습니까? –

+1

수정. 세미콜론이 누락되었습니다. 도와 주셔서 감사합니다! –