2008年9月2日 星期二

[PHP]利用巢狀函數轉換進位

===HTML部份語法===
< body >

< h2>請輸入一個整數:< /h2>
< form name="form1" method="post" action="test16.php">

< p>
< input type="text" name="number">
< /p>
< p>
< input type="submit" name="submit" value="送出">
< input type="reset" name="reset" value="reset" id="reset" >

< /p>


< /form>
< /body>

==================PHP部份============
< ?php
$n=$_POST[number];
function nest_transform($n)
{
function bin($n)
{
return decbin($n);
}

function oct($n)
{
return decoct($n);
}

function hex($n)
{
return dechex($n);
}

echo "< table border=2 width=80%>";
echo "< tr>二進位< /th>< td>".bin($n)."< /td>< /tr>";
echo "< tr>< th>八進位< /th>< td>".oct($n)."< /td>< /tr>";
echo "< tr>< th>十六進位< /th>< td>".hex($n)."< /td>< /tr>";


}

echo $n."< /br>";
nest_transform($n);


?>

沒有留言: