Skip to content

Instantly share code, notes, and snippets.

@co3k
Created October 13, 2010 13:54
Show Gist options
  • Save co3k/624064 to your computer and use it in GitHub Desktop.
Save co3k/624064 to your computer and use it in GitHub Desktop.
<?php
/**
* Copyright 2010 Kousuke Ebihara
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
define('LOCAL_FILENAME', './unicode-6.0.0.txt');
define('MAX_LINE', 23697);
$filename = is_file(LOCAL_FILENAME) ? LOCAL_FILENAME : 'http://www.unicode.org/Public/6.0.0/ucd/UnicodeData.txt';
$fh = fopen($filename, 'r');
$max_line = MAX_LINE;
$line = rand(1, $max_line);
// must be refactored
$code = null;
if (isset($_GET['code']))
{
$code = $_GET['code'];
$line = $max_line;
}
$data = '';
for ($i = 0; $i < $line; $i++)
{
$data = trim(fgets($fh));
$data = explode(';', $data);
if (!is_null($code) && $data[0] == $code)
{
break;
}
}
fclose($fh);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>Unicode</title>
<style type="text/css"><!--
body * { text-align: center; }
dt { font-size: 200px; }
--></style>
</head>
<body>
<h1>Unicode</h1>
<h2><a href="./unicode.php?code=<?php echo $data[0] ?>">U+<?php echo $data[0] ?></a></h2>
<dl>
<dt><?php echo mb_convert_encoding(pack('H*', $data[0]), 'UTF-8', 'UCS-2') ?></dt>
<dd><?php echo $data[1] ?></dd>
</dl>
<p><a href="http://gist.github.com/624064">code</a></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment