해결책 :쓰기 파일
$output = '–– € ––';
//written like this php 5 does not understand because it interprets it as single-byte chars.
//so i found the function below to write a multi-byte char in a string.
//unicode version of php's chr()
function uchr ($codes) {
if (is_scalar($codes)) $codes= func_get_args();
$str= '';
foreach ($codes as $code) $str.= html_entity_decode('&#'.$code.';',ENT_NOQUOTES,'UTF-8');
return $str;
}
//decimal values of unicode chars: – 8211 - 8211, [space] 32, € 8364,[space] 32, – 8211 - 8211
$output = uchr(8211,8211,32,8364,32,8211,8211);
//or
$output = uchr(8211,8211).' '.uchr(8364).' '.uchr(8211,8211);
echo $output;
질문 : 간단한 파일에 이러한 특수 문자를 쓸 수있는 방법
? 내가 브라우저 http://mydomain.com/upload/myfile.txt에서이 파일을 액세스하는 경우
$file = "./upload/myfile.txt";
$output = "–– € ––".PHP_EOL; // the "–" is not an underscore _ or - but –
file_put_contents($file, $output);
난 단지 "문자"얻는다.
그러나 Zend Developer 또는 내 로컬 텍스트 편집기 (OSX)를 사용하여 "- € -"를 저장하고이 모든 것을 완벽하게 업로드하면됩니다. 브라우저가 올바르게 표시합니다.
어떻게 PHP로이 작업을 수행 할 수 있습니까? 그것은 PHP는 내 맥북보다 파일을 작성하는 다른 방법을 사용하는 것. php의 표준이 UTF-8이라고 생각하고 로컬 텍스트 편집기에서 UTF-8로 파일을 저장했다고 생각했습니다.
EXTRA 정보 : 업로드 폴더의 htaccess로 파일에 내가 쓴 :
AddDefaultCharset utf-8
AddCharset utf-8 .txt
달리 파이어 폭스에서 불을 지르고 애드온이 캐릭터 세트가 지정되지 않은 메시지를 주었다.
어떤 아이디어가 있습니까? 내 업로드 된 파일이 올바르게 표시되므로 파일을 저장하는 것과 관련이 있습니다. 같은 파일을 저장하는 동안
나는 다른 옵션을 시도 :$output = mb_convert_encoding($output, 'UTF-8', 'OLD-ENCODING');
와 PHP의의 iconv 기능, 그러나 나는 해결책을 찾을 수 없습니다.
모든 도움을 주시면 대단히 감사하겠습니다.
편집 : 난 내 업로드 된 파일의 콘텐츠를하고 에코 경우 다음은 소스 코드에로
$output = file_get_contents('./upload/myuploadedfile.txt',FILE_USE_INCLUDE_PATH);
//it show correctly –– € ––
$output = $output[1]; //it shows a �
$output = $output[3]; //it shows a �
echo $output;
가능한 [UTF-8 형식으로 파일을 쓰는 방법?] (http://stackoverflow.com/questions/4839402/how-to-write-file-in-utf-8-format) –
아니요, 나는 그 포스트에 의해왔다. 그러나 그것은 나의 경우에는 효과가 없다. – fellowworldcitizen