Skip to content

Instantly share code, notes, and snippets.

@jiskanulo
Last active August 29, 2015 13:56
Show Gist options
  • Save jiskanulo/9173498 to your computer and use it in GitHub Desktop.
Save jiskanulo/9173498 to your computer and use it in GitHub Desktop.
初めて自分のために書いたphp
<?php
function h($var) {
return htmlspecialchars($var, ENT_QUOTES, 'Shift_JIS');
}
function r($key, $escape=true) {
$value = (!empty($_REQUEST[$key])) ? $_REQUEST[$key] : null;
if ($escape!==true) return $value;
return h($value);
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="content-style-type" content="text/css">
<meta http-equiv="content-script-type" content="text/javascript">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<link rel="stylesheet" href="./style.css" media="screen">
<title>あのあれ</title>
</head>
<body>
<h1>あのあれ</h1>
<form action="./" method="get">
<h2>datetime</h2>
<table summary="unixtimestamp,datetimeの変換">
<col style="width:140px;">
<col style="width:400px;">
<col style="width:60px;">
<tr>
<th>unixtimestamp</th>
<td><input type="text" name="ut" value="<?php echo r('ut'); ?>" style="width:200px;"></td>
<td><input type="submit" value=" ⇒ "></td>
<td><?php echo h(date('Y-m-d H:i:s', intval(r('ut', false)))); ?></td>
</tr>
<tr>
<th>datetime</th>
<td><select name="dy">
<?php
for ($i = date('Y'); $i <= date('Y')+4; $i++) {
$selected = (r('dy', false) == $i) ? ' selected' : '';
echo '<option value="' . h($i) . '"' . $selected . '>' . h(sprintf('%04d', $i)) . '</option>';
}
?>
</select>
-
<select name="dm">
<?php
for ($i = 1; $i <= 12; $i++) {
$selected = (r('dm', false) == $i) ? ' selected' : '';
echo '<option value="' . h($i) . '"' . $selected . '>' . h(sprintf('%02d', $i)) . '</option>';
}
?>
</select>
-
<select name="dd">
<?php
for ($i = 1; $i <= 31; $i++) {
$selected = (r('dd', false) == $i) ? ' selected' : '';
echo '<option value="' . h($i) . '"' . $selected . '>' . h(sprintf('%02d', $i)) . '</option>';
}
?>
</select>
&nbsp;
<select name="dh">
<?php
for ($i = 0; $i <= 23; $i++) {
$selected = (r('dh', false) == $i) ? ' selected' : '';
echo '<option value="' . h($i) . '"' . $selected . '>' . h(sprintf('%02d', $i)) . '</option>';
}
?>
</select>
:
<select name="di">
<?php
for ($i = 0; $i <= 59; $i++) {
$selected = (r('di', false) == $i) ? ' selected' : '';
echo '<option value="' . h($i) . '"' . $selected . '>' . h(sprintf('%02d', $i)) . '</option>';
}
?>
</select>
:
<select name="ds">
<?php
for ($i = 0; $i <= 59; $i++) {
$selected = (r('ds', false) == $i) ? ' selected' : '';
echo '<option value="' . h($i) . '"' . $selected . '>' . h(sprintf('%02d', $i)) . '</option>';
}
?>
</select>
</td>
<td><input type="submit" value=" ⇒ "></td>
<td><?php echo h(mktime(intval(r('dh', false)), intval(r('di', false)), intval(r('ds', false)), intval(r('dm', false)), intval(r('dd', false)), intval(r('dy', false))));?></td>
</tr>
</table>
<h2>hash</h2>
<table summary="hash作成">
<col style="width:140px;">
<col style="width:220px;">
<col style="width:60px;">
<tr>
<th>md5</th>
<td><input type="text" name="md5" value="<?php echo r('md5'); ?>" style="width:200px;"></td>
<td><input type="submit" value=" ⇒ "></td>
<td><?php echo h(md5(r('md5', false))); ?></td>
</tr>
<tr>
<th>sha1</th>
<td><input type="text" name="sha1" value="<?php echo r('sha1'); ?>" style="width:200px;"></td>
<td><input type="submit" value=" ⇒ "></td>
<td><?php echo h(sha1(r('sha1', false))); ?></td>
</tr>
</table>
<h2>url</h2>
<table summary="urlencode,decode">
<col style="width:140px;">
<col style="width:220px;">
<col style="width:60px;">
<tr>
<th>urldecode</th>
<td><input type="text" name="ud" value="<?php echo r('ud'); ?>" style="width:200px;"></td>
<td><input type="submit" value=" ⇒ "></td>
<td><?php echo h(urldecode(r('ud', false))); ?></td>
</tr>
<tr>
<th>urlencode</th>
<td><input type="text" name="ue" value="<?php echo r('ue'); ?>" style="width:200px;"></td>
<td><input type="submit" value=" ⇒ "></td>
<td><?php echo h(urlencode(r('ue', false))); ?></td>
</tr>
</table>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment