외부 url 정보 가져오기 문의 드립니다.

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!
외부 url 정보 가져오기 문의 드립니다.

QA

외부 url 정보 가져오기 문의 드립니다.

답변 3

본문

외부 사이트(url)  title / description / keywords

정보를 가져 오는 소스를 발견해서 한번 써 보려 하는데....

한글이 깨져서 나오고 있습니다....ㅠ.ㅠ

 

<?

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

    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
   

 


    $data = curl_exec($ch);

    curl_close($ch);

    return $data;
}

$html = file_get_contents_curl("http://www.naver.com/" ) ;

//parsing begins here:
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');

//get and display what you need:
$title = $nodes->item(0)->nodeValue;

$metas = $doc->getElementsByTagName('meta');

for ($i = 0; $i < $metas->length; $i++)
{
    $meta = $metas->item($i);
    if($meta->getAttribute('name') == 'description')
        $description = $meta->getAttribute('content');
    if($meta->getAttribute('name') == 'keywords')
        $keywords = $meta->getAttribute('content');
}

 

?>

<?php

echo "Title: $title". '<br/><br/>';
echo "Description: $description". '<br/><br/>';
echo "Keywords: $keywords";

?>

 

 

 

결과물

 

Title: NAVER

Description: 챘혙짚챙혶쨈챘짼혙 챘짤혬챙혶쨍챙혰혨챙혙혵 챘혢짚챙혯혩챠혮혵 챙혻혮챘쨀쨈챙혲? 챙혵혻챙혳짤챠혮혵 챙쨩짢챠혚혨챙쨍혻챘짜쩌 챘짠혣챘혗혱 챘쨀쨈챙혙쨍챙혳혬

Keywords:

 

이런식으로 한글이....

혹시 어디를 수정 해야 하는지 아시는분 있으세요ㅠ.ㅠ

이 질문에 댓글 쓰기 :

답변 3

$charSet = mb_check_encoding($description, "EUC-KR"); 
if($charSet){
       $description = iconv("EUC-KR", "UTF-8", $description);
}

 

위 소스로 description을 변경해보시고, 안되시면 EUC-KR과 UTF-8을 반대로 적용해보세요~

네이버니까 당연히 utf-8 로 가지고 올텐데요..

그냥 브라우즈가 euc-kr로 보여지는것 아닐까요?  부라우즈 인코딩을 다르게하거나 다른 브라우로 보시거나

크롬에서는 이렇게 보입니다.

^^2943640179_1519959066.3643.jpg

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 124,170
© SIRSOFT
현재 페이지 제일 처음으로