phpでローマ字からひらがなとかカタカナに変換したい
以外に情報なかったからめも
精度100%は無理やけど、とりあえず地味に書くのだるいーって人向け
案件用のコードだから細かいとこはカスタマイズしてくだちい
<?php
$csv = file(dirname(__FILE__).'/term.csv');
$csv_header = $csv[0];
$csv_body = array_splice($csv, 1);
$array = [];
foreach ($csv_body as $row) {
$row_array = explode(',', $row);
array_push($array, $row_array);
}
$ar = [];
for ($i=0; $i < count($array); $i++) {
// 県取得
$p = explode(' ', $array[$i][1]);
if(!isset($ar[$p[0]])) {
$ar[$p[0]] = array();
}
array_push($ar[$p[0]], $array[$i]);
}
foreach($ar as $key => $value) {
foreach ($value as $num => $v) {
$ar[$key][$num][5] = '';
$ar[$key][$num][5] = str_replace('kka','っか', $ar[$key][$num][2]);
$ar[$key][$num][5] = str_replace('kki','っき', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('kku','っく', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('kke','っけ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('kko','っこ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ssa','っさ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('sshi','っし', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ssu','っす', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('sse','っせ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('sso','っそ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('tta','った', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('tti','っち', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ttu','っつ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('tte','って', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('tto','っと', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ppa','っぱ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ppi','っぴ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ppu','っぷ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ppe','っぺ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ppo','っぽ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ga','が', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('gi','ぎ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('gu','ぐ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ge','げ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('go','ご', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('za','ざ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ji','じ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('zu','ず', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ze','ぜ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('zo','ぞ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('da','だ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ji','ぢ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('zu','づ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('de','で', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('do','ど', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ba','ば', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('bi','び', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('bu','ぶ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('be','べ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('bo','ぼ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('pa','ぱ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('pi','ぴ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('pu','ぷ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('pe','ぺ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('po','ぽ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('kya','きゃ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('kyu','きゅ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('kyo','きょ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('sha','しゃ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('shu','しゅ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('sho','しょ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('cha','ちゃ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('chu','ちゅ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('cho','ちょ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('nya','にゃ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('nyu','にゅ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('nyo','にょ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('hya','ひゃ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('hyu','ひゅ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('hyo','ひょ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('mya','みゃ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('myu','みゅ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('myo','みょ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('rya','りゃ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ryu','りゅ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ryo','りょ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('gya','ぎゃ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('gyu','ぎゅ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('gyo','ぎょ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ja','じゃ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ju','じゅ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('jo','じょ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('bya','びゃ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('byu','びゅ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('byo','びょ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('pya','ぴゃ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('pyu','ぴゅ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('pyo','ぴょ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('chi','ち', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('tsu','つ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ka','か', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ki','き', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ku','く', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ke','け', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ko','こ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('sa','さ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('shi','し', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('si','し', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('su','す', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('se','せ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('so','そ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ta','た', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('te','て', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('to','と', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('na','な', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ni','に', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('nu','ぬ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ne','ね', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('no','の', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ha','は', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('hi','ひ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('fu','ふ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('he','へ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ho','ほ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ma','ま', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('mi','み', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('mu','む', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('me','め', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('mo','も', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ya','や', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('yu','ゆ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('yo','よ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ra','ら', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ri','り', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ru','る', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('re','れ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('ro','ろ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('wa','わ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('a','あ', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('i','い', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('u','う', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('e','え', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('o','お', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('n','ん', $ar[$key][$num][5]);
$ar[$key][$num][5] = str_replace('m','ん', $ar[$key][$num][5]);
}
}
foreach ($ar as $key => $value) {
$sort = [];
foreach ($value as $num => $v) {
$sort[$num] = $v[5];
}
array_multisort($sort, SORT_ASC, $ar[$key]);
}
めんどいなーーって人に使ってもらえれば幸い。
この記事が気に入ったらサポートをしてみませんか?