2016-09-02 7 views
1
$str = "https://www.google.com/search?q=sd"; 
echo file_get_contents($str); 

하지만 물음표처럼 보여주는 UTF-8의 chracters의 출력과 같은 UTF-8의 문자를 보여줍니다.file_get_contents 물음표 난 함수 file_get_contents와 구글에서 페이지를로드하려고

여기에 소개 된 모든 가능성을 시도했습니다. file_get_contents() converts UTF-8 to ISO-8859-1 그러나 문제는 해결되지 않았습니다.

매우 도움이된다고 생각합니다.

업데이트 :이 문제는 Google을 통해 존재하는 것을 볼 수

가 다른 사이트의 콘텐츠가 올바르게 표시됩니다.

enter image description here

+0

그냥 PHP 스크립트가 UTF-8로 구문 분석되도록 헤더를 보내시겠습니까? – ByteHamster

+0

어떻게하면됩니까? – ABE

+1

첫 번째 진술 (html을 보내기 전에)은'header ("Content-Type : text/html; charset = utf-8"),' – ByteHamster

답변

2

[PHP]

//charset.php?case=1 
//charset.php?case=2 
//charset.php?case=3 

$case = isset($_GET['case']) ? $_GET['case'] : 1; 

if(!in_array($case,range(1,3))) $case = 1; 


if($case==1) { 
    header("Content-type: text/html; charset=tis-620"); //http://htmlpurifier.org/docs/enduser-utf8.html 
    $str = "https://www.google.co.th/search?q=sd"; 
} 

if($case==2) { 
    header("Content-type: text/html; charset=ISO-8859-1"); 
    $str = "https://www.google.de/search?q=sd"; 
} 

if($case==3) { 
    header("Content-type: text/html; charset=ISO-8859-9"); 
    $str = "https://www.google.com.tr/search?q=sd"; 
} 


$data = file_get_contents($str); 
echo $data; 

[/ php에]

볼 수 있듯이 한 번 시도 .. PHP 헤더의 올바른 문자셋은 솔루션입니다.

+0

와우! 고마워요! 일이야! – ABE

1

은 당신이 나를 위해 일한이 코드 ..

<?php 
$abc = array('http' => array('header' => 'Accept-Charset: UTF-8, *;q=0')); 
$some_context = stream_context_create($abc); 
$filename = "https://www.google.com/search?q=sd"; 
echo file_get_contents($filename, false, $some_context); 
    ?> 
+0

고마워요,하지만 다시 시도해 봤는데 저를 위해 작동하지 않았습니다 : ( – ABE

+1

응답이 동일합니까? 특수 문자와 같은 물음표가 표시되고 있습니까? –

+1

@ABE가 코드를 변경했습니다. –