首页 > 代码库 > 放假(六)

放假(六)

今天跑出去玩了,没怎么预习啊,就把基本数据类型看完了,做了一个进制转换的功能,就和那个计算器差不多的!

<!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="http://www.mamicode.com/<?php echo $num ?>">
<select name="kinds">
    <option value="http://www.mamicode.com/10to2" <?php if($kinds == "10to2") echo "selected = selected"; ?> >10to2</option>
    <option value="http://www.mamicode.com/10to8" <?php if($kinds == "10to8") echo "selected = selected"; ?> >10to8</option>
    <option value="http://www.mamicode.com/10to16" <?php if($kinds == "10to16") echo "selected = selected"; ?> >10to16</option>
    <option value="http://www.mamicode.com/2to10" <?php if($kinds == "2to10") echo "selected = selected"; ?> >2to10</option>
    <option value="http://www.mamicode.com/8to10" <?php if($kinds == "8to10") echo "selected = selected"; ?>>8to10</option>
    <option value="http://www.mamicode.com/16to10" <?php if($kinds == "16to10") echo "selected = selected"; ?>>16to10</option>
</select>
    <input type="submit" value="http://www.mamicode.com/转换">
    <input type="text" value="http://www.mamicode.com/<?php echo $res; ?>">
</form>

</body>
</html>

 

放假(六)