放假(六)
今天跑出去玩了,没怎么预习啊,就把基本数据类型看完了,做了一个进制转换的功能,就和那个计算器差不多的!
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>进制转换</title>
</head>
<body>
<?php
$res = "";
$num = '';
$kinds = '';
if(!empty($_POST)){
$num = $_POST['num'];
$kinds = $_POST['kinds'];
switch ($kinds){
case "10to2":
$res = decbin($num);
break;
case "10to8":
$res = decoct($num);
break;
case "10to16":
$res = dechex($num);
break;
case "2to10":
$res = bindec($num);
break;
case "8to10":
$res = octdec($num);
break;
default:
$res = hexdec($num);
}
}
?>
<form method="post">
数:<input type="text" name="num" value="<?php echo $num ?>">
<select name="kinds">
<option value="10to2" <?php if($kinds == "10to2") echo "selected = selected"; ?> >10to2</option>
<option value="10to8" <?php if($kinds == "10to8") echo "selected = selected"; ?> >10to8</option>
<option value="10to16" <?php if($kinds == "10to16") echo "selected = selected"; ?> >10to16</option>
<option value="2to10" <?php if($kinds == "2to10") echo "selected = selected"; ?> >2to10</option>
<option value="8to10" <?php if($kinds == "8to10") echo "selected = selected"; ?>>8to10</option>
<option value="16to10" <?php if($kinds == "16to10") echo "selected = selected"; ?>>16to10</option>
</select>
<input type="submit" value="转换">
<input type="text" value="<?php echo $res; ?>">
</form>
</body>
</html>

浙公网安备 33010602011771号