2012-04-22 1 views
0

파일의 모든 문자를 PHP의 ASCII 코드로 변환하고 싶습니다. 나는 ord 기능을 알고 있지만 전체 파일에 대해 수행 할 기능이 있는지 여부를 알고 있습니까?파일의 모든 문자를 PHP의 ascii 번호로 변환하는 방법

+0

이 ... PHP는 __almost__ 모든 것을 내장 기능을 제공, 모든 것이 –

+0

에 대해 내가 쓴하지만 내 서버 하고 set_time_limit (3000) 중지; $ file1 = file_get_contents ("v1.3gp"); $ file2 = str_split ($ file1); foreach ($ file2는 $ file3) { $ file4 = ord ($ file3); $ file5 = $ file5. $ file4; } file_put_contents ("a3.txt", $ file5); – Shan

답변

0

iconv에서 작업

http://php.net/manual/de/function.iconv.php

가 다른 하나에 문자열에서 지정된 문자 세트의 문자를 convertes을 할 수 있습니다. 1 : 1로 변환 할 수없는 char에 대한 TRANSLIT 및/또는 IGNORE 스페셜을 살펴보십시오.

문자열로 파일을 가져 오려면 file_get_contents를 사용하고 iconv 등이 file_put_contents와 함께 적용된 후에 저장하십시오. 당신이 스스로를 쓰기 만하면

0
$inputFile = fopen("input.txt", "rb"); 
$outputFile = fopen("output.txt", "w+"); 

while (!feof($inputFile)) { 
    $inputBlock = fread($inputFile, 8192); 
    $outputBlock = ''; 
    $inputLength = strlen($inputBlock); 
    for ($i = 0; $i < $inputLength; ++$i) { 
     $outputBlock .= str_pad(dechex(ord($inputBlock{$i})),2,'0',STR_PAD_LEFT); 
    } 
    fwrite($outputFile,$outputBlock); 
} 

fclose($inputFile); 
fclose($outputFile); 
관련 문제