Last active
September 1, 2023 09:17
-
-
Save naoa/7858360 to your computer and use it in GitHub Desktop.
from kanji to katakana convert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$input_file = $argv[1]; | |
if($argc >= 3){ | |
$output_file = $argv[2]; | |
} | |
else{ | |
$output_file = ""; | |
} | |
$conv = "./converter-main -i"; | |
$dict = "dict/bccwj4"; | |
$fp = fopen($input_file, 'r'); | |
if($output_file != ""){ | |
$fw = fopen($output_file, 'a+'); | |
} | |
while (!feof($fp)){ | |
$line = fgets($fp); | |
$line = str_replace(array("\r\n","\r","\n"),'',$line); | |
$cmd = 'echo ' . $line . ' | ' . $conv . ' ' . $dict; | |
$af_str = exec($cmd); | |
if($af_str != ""){ | |
$af_str = mb_convert_kana($af_str, "C", "UTF-8"); | |
if($output_file != ""){ | |
fwrite($fw,$af_str . "\n"); | |
} | |
else{ | |
echo $af_str . "\n"; | |
} | |
} | |
} | |
fclose($fp); | |
if($output_file != ""){ | |
fclose($fw); | |
} | |
echo "Done.\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
シルバ