Skip to content

Instantly share code, notes, and snippets.

@ShinichiU
Created September 9, 2015 00:08
Show Gist options
  • Save ShinichiU/945612d5bd8fb29bd42e to your computer and use it in GitHub Desktop.
Save ShinichiU/945612d5bd8fb29bd42e to your computer and use it in GitHub Desktop.
Unicode コードポイントの範囲を指定して対象の文字を取得するスクリプト
<?php
/**
* Cordpoint charcter generate v1.0.0
* http://test.nuts-choco.com/cordpoint.php
*
* Shinichi Urabe <[email protected]>
* Released under the MIT license
* https://tldrlegal.com/license/mit-license
*
* Date: 2015-09-09T16:01Z
*/
// function define.
function escape($str)
{
return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
}
function get_parameter($key, $default)
{
return isset($_GET[$key]) ? $_GET[$key] : $default;
}
function get_cordpoint_bin($min, $max)
{
for ($i = $min; $i <= $max; $i++)
{
$cordpoint = sprintf('U+%s', strtoupper(dechex($i)));
$bin = json_decode(sprintf('"\\u%s"', dechex($i)), true);
yield $cordpoint => $bin;
}
}
function get_plain_script_name()
{
$filename = basename(__FILE__);
$path = preg_replace(sprintf('/%s.*/i', preg_quote($filename, '/')), '', $_SERVER['SCRIPT_NAME']);
return $path.$filename;
}
if (isset($_POST['download']))
{
$file = file_get_contents(__FILE__);
header('Content-Disposition: inline; filename="'.basename(__FILE__).'"');
header('Content-Length: '.strlen($file));
header('Content-Type: application/octet-stream');
echo $file;
exit;
}
// init.
$keyList = ['min' => '0x2669', 'max' => '0x26b2', 'tableMax' => 10];
foreach ($keyList as $key => $default)
{
$$key = intval(get_parameter($key, $default), 0);
}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>コードポイントの範囲から文字リストを取得</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<form class="form-inline" action="<?= escape(get_plain_script_name()) ?>" method="get">
<?php foreach ($keyList as $key => $default): ?>
<div class="form-group">
<?php $escapedKey = escape($key) ?>
<label for="<?= $escapedKey ?>"><?= $escapedKey ?></label>
<input id="<?= $escapedKey ?>" class="form-control" type="text" value="<?= escape(get_parameter($key, $default)) ?>" name="<?= $escapedKey ?>" />
</div>
<?php endforeach ?>
<button type="submit" class="btn btn-default">送信</button>
</form>
<br>
<form class="form" action="<?= escape(get_plain_script_name()) ?>" method="post">
<input type="hidden" name="download" value="1" />
<button type="submit" class="btn btn-default">スクリプトファイルのダウンロード</button>
</form>
<div class="table-responsive">
<?php if ($max > $min && $tableMax > 0): ?>
<table class="table">
<tbody>
<?php $j = 0 ?>
<?php $k = 0 ?>
<?php foreach (get_cordpoint_bin($min, $max) as $cordpoint => $bin): ?>
<?php $j++ ?>
<?php if ($j % $tableMax === 1): ?><tr>
<?php endif ?>
<td><?= escape($bin) ?><br><small>(<em><?= escape($cordpoint) ?></em>)</small></td>
<?php if (($amari = $j % $tableMax) === 0): ?></tr>
<?php $k++ ?><?php endif ?>
<?php endforeach ?>
<?= 0 !== $amari ? ($k !== 0 ? str_repeat('<td>&nbsp;</td>', $tableMax - $amari).PHP_EOL : '').'</tr>' : '' ?>
</tbody>
</table>
<?php else: ?>
値が正しくないです
<?php endif ?>
</div>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment