테스트 사이트 - 개발 중인 베타 버전입니다

ChatGPT 달았어요,  그런데 응답을 한글로 했는데 깨져 보임이다. 채택완료

alexseo 2년 전 조회 7,048

ChatGPT 달았어요, 

그런데 질문 및 응답을 한글로 했는데 깨져 보임이다.

한글이 정상적으로 나오게 하려면 어떻게 해야하나요?

소스는 다음과 같습니다.

 

-----------------------------------------------------

                ChatGPT Form      

     
       
             
     
     
             
   
     

 

-----------------------------------------------------

 

 

댓글을 작성하려면 로그인이 필요합니다.

답변 6개

채택된 답변
+20 포인트
그누위즈

파일자체의 인코딩이 utf-8이 맞는지 확인해보세요.

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

a
2년 전

네, 이상합니다.

저는 안되는데요

다른 문제가 있는 것 같습니다.

답변 감사합니다.

 

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

들레아빠

보여주신 코드로 실행한 화면입니다.

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

a
2년 전

gpt-run.php 의 함수 코드에서 한글로 해야 하나요?

 

소스 코드

 

$api_key = "";

function translate($content, $source='ko', $target='en') {     $handle = curl_init();     curl_setopt($handle, CURLOPT_URL,'https://www.googleapis.com/language/translate/v2');     curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);     curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);     $data = array('key' => "API Key",                     'q' => $content,                     'source' => $source,                     'target' => $target);     curl_setopt($handle, CURLOPT_POSTFIELDS, preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', http_build_query($data)));     curl_setopt($handle,CURLOPT_HTTPHEADER,array('X-HTTP-Method-Override: GET'));     $response = curl_exec($handle);     $responseDecoded = json_decode($response, true);     $responseCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);     curl_close($handle);     return  $responseDecoded['data']['translations'][0]['translatedText']; }

function ko2en($content) {     return translate($content, 'ko', 'en'); }

function en2ko($content) {     return translate($content, 'en', 'ko'); }

$url = "https://api.openai.com/v1/completions";

// "What is the capital of France?" $prompt = filter_var($_POST["prompt"], FILTER_SANITIZE_STRING);;

$data = array(     "model" => "text-davinci-003",       "prompt" => $prompt,     "max_tokens" => 3000,     "temperature" => 0.5, );

$data_string = json_encode($data);

$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_HTTPHEADER, array(     "Content-Type: application/json",     "Authorization: Bearer $api_key",     "Content-Length: " . strlen($data_string)) );

$output = curl_exec($ch); curl_close($ch); // print_r($output);

$output_json = json_decode($output, true); $response = $output_json["choices"][0]["text"];

// echo $response; ?>

 

 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

들레아빠
2년 전
지금 이 파일 저장을 할 때 UTF-8로 저장을 하세요. 코드는 이상 없이 잘 됩니다.

댓글을 작성하려면 로그인이 필요합니다.

a
2년 전

   

위의 부분에 하면 되나요?

위와 같이 했는데 한글이 깨지네요.

그리고 저장을 아래와 같이 => Unicode (UTF-8) 로 했습니다.

그러데도 한글이 깨짐니다. 

감사합니다.

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

2년 전

문서를 euc-kr 로 저장했다면 utf-8로 저장해보세요~

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인