2012-09-30 3 views
0

yahoo의 금융 주식 시세를 사용하여 api에서 주식 시세 데이터를 가져옵니다. 지금이 내 로컬 서버 (로컬 호스트), 즉 $ 값이 밖으로 에코됩니다에 완벽하게 잘 작동yahoo 주식 위젯 원격 통화 PHP를 사용하여

$data = file_get_contents("http://quote.yahoo.com/d/quotes.csv?s=appl&f=sl1d1t1c1ohgv&e=.csv"); 
$values = explode(",", $data); 
echo '<pre>'; 
print_r($values);  

를 사용하여 데이터를 잡아합니다. 그러나이 파일을 내 서버에 업로드하면 URL : http://quote.yahoo.com/d/quotes.csv?s=appl&f=sl1d1t1c1ohgv&e=.csv이 인쇄됩니다. 서버에 file_get_contents와 관련된 문제가 있음을 알고 있습니다. 심지어 allow_url_fopen은 서버에서 'ON'으로 설정됩니다. 서버 측에서 문제를 파악할 수없는 것 같습니다.

답변

0

당신은 아마 서버 설정이 file_get_contents()를 사용 두지 않을에하는 데 문제가 있습니다. PHP에서 curl은 다른 도메인의 콘텐츠를 가져올 때 친구가됩니다.

난 그냥이 멋진 작은 조각을 발견 : http://snipplr.com/view/4084

그것은 file_get_contents()의 기능을 복제 할 수있는 기능입니다을하지만 curl 사용

function file_get_contents_curl($url) { 
    $ch = curl_init(); 

    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser. 
    curl_setopt($ch, CURLOPT_URL, $url); 

    $data = curl_exec($ch); 
    curl_close($ch); 

    return $data; 
} 

새 코드는 다음과 같습니다

$data = file_get_contents_curl("http://quote.yahoo.com/d/quotes.csv?s=appl&f=sl1d1t1c1ohgv&e=.csv"); 
$values = explode(",", $data); 
echo '<pre>'; 
print_r($values);  
+0

그 일을 시도했는데 ... 여전히 같은 문제에 직면하고 있습니다. – user1411837

관련 문제