码迷,mamicode.com
首页 > 其他好文 > 详细

放假(六)

时间:2016-12-21 02:42:35      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:转换   pos   user   进制   post   ext   put   char   title   

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

<!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>

 

放假(六)

标签:转换   pos   user   进制   post   ext   put   char   title   

原文地址:http://www.cnblogs.com/panbee/p/6206072.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!