Skip to content

Instantly share code, notes, and snippets.

@ko31
Created December 20, 2016 12:24
Show Gist options
  • Save ko31/953e8a71e9fe3c199d0f5acf4678fece to your computer and use it in GitHub Desktop.
Save ko31/953e8a71e9fe3c199d0f5acf4678fece to your computer and use it in GitHub Desktop.
【PHP】棋士名を分解してどの文字が何回使われているか取得
<?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