Created
December 20, 2016 12:24
-
-
Save ko31/953e8a71e9fe3c199d0f5acf4678fece to your computer and use it in GitHub Desktop.
【PHP】棋士名を分解してどの文字が何回使われているか取得
This file contains hidden or 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 | |
$data = file_get_contents("kishi_all.json"); | |
$data = json_decode($data); | |
$list = array(); | |
foreach ($data as $kishi) { | |
$length = mb_strlen($kishi->name, 'UTF-8'); | |
for($i=0; $i<$length; $i++) { | |
$char = mb_substr($kishi->name, $i, 1, 'UTF-8'); | |
if (isset($list[$char])) { | |
$list[$char]++; | |
} else { | |
$list[$char] = 1; | |
} | |
} | |
} | |
$tmp = array(); | |
foreach ($list as $k => $v) { | |
$tmp[] = "['".$k."', ".($v*5)."]"; | |
} | |
$src = 'var data = ['; | |
$src .= implode(',', $tmp); | |
$src .= '];'; | |
file_put_contents('data.js', $src); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment