I'm here about the making of the program will explain the conversion of numbers in php.
Where at first view appears web log, or so-called validator program, after the click 'go' he would immediately open the web converter combination.
This coding set of global variables, the name of the input variables, input gender, and check whether the data has been loaded correctly or not.
1. First we have to do is open up NetBeans.
2. Next create a new project with the name 'a.php'.
3. After that, write a script like this and you may modify according to the liver.
<?php
if(isset($_POST['submit'])){//isset : penekanan form
$nama=$_REQUEST['nama'];
if(isset($_POST['gender'])){
$gender=$_REQUEST['gender'];
}
else{
$gender='';
}
$cek='';
}
else{
$nama='';
$gender='';
$cek='Silahkan Isi Form Di Bawah ini Dahulu, Sebelum Masuk ke Konverter';
}
?>
4. Furthermore, to set the display, please fill in the following css code between the head tags.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Konversi Bilangan ke Biner,Oktal,Hexa</title>
<style type="text/css">
body{
background: url('windows-7-wallpaper.jpg') no-repeat;
}
.a{
font-family: Gill Sans MT;
padding-top: 5%;
padding-left: 65%;
padding-right: 5%;
color: orange;
text-align: center;
}
.b{
font-family: Gill Sans MT;
color:blue;
text-align: center;
}
form {
padding-bottom: 40%;
padding-left: 65%;
padding-right: 5%;
}
form input.highlight{
background: blue;
border-radius:5px;
padding: 5px;
}
form input.highlight:focus {
background: whitesmoke;
border-radius:5px;
box-shadow:2px 2px 5px orange;
}
</style>
</head>
5. Furthermore enter the following code to set the login web design.
<body>
<div>
<h2 class='a'><?php echo $cek ?></h2>
</div>
<br>
<form action="b.php" method="post" name="form1">
<p>
<h3 class='b'>
Nama : <input class='highlight' placeholder="Nama kamu siapa ?" required="required" type="text" name="nama" size ="30" value="<?php echo $nama ?>"/></h3>
</p>
<p>
<h3 class='b'>
Pastikan Jenis Kelamin ada : <br>
<input type="radio" name="gender" value="L"
<?php ($gender=="L")? print 'checked=""' : print ''; ?>/>
Laki-Laki<br>
<input type="radio" name="gender" value="P"
<?php ($gender=="P")? print 'checked=""' : print ''; ?>/>
Perempuan
</h3>
</p>
<center><input type="submit" name="submit" value="Masuk"></center>
</form>
</body>
</html>
6. That way, the a.php as web validator is complete.
Now it makes b.php webpage, and here are the steps.
1. Create a new php web page, give it a name that will be web b.php converter combination.
2. Fill in the following code above the html code, to set the global variables php program, the decimal input and conversion options.
<?php
if(isset($_POST['submit1'])){
$decimal=$_REQUEST['decimal'];
if(isset($_POST['pilih'])){
$pilih=$_REQUEST['pilih'];
}
else{
$pilih='';
}
}
else{
$decimal='';
$pilih='';
}
?>
3. Next enter the following code, the display manager (css) from b.php.
4. Furthermore, to set the display, please fill in the following css code between the head tags.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Konversi Bilangan ke Biner,Oktal,Hexa</title>
<style type="text/css">
body{
background: url('windows-7-wallpaper.jpg') no-repeat;
}
.a{
font-family: Gill Sans MT;
padding-top: 5%;
padding-left: 65%;
padding-right: 5%;
color: orange;
text-align: center;
}
.b{
font-family: Gill Sans MT;
color:blue;
text-align: center;
}
form {
padding-bottom: 40%;
padding-left: 65%;
padding-right: 5%;
}
form input.highlight{
background: blue;
border-radius:5px;
padding: 5px;
}
form input.highlight:focus {
background: whitesmoke;
border-radius:5px;
box-shadow:2px 2px 5px orange;
}
</style>
</head>
5. Furthermore enter the following code to set the login web design.
<body>
<div>
<h2 class='a'><?php echo $cek ?></h2>
</div>
<br>
<form action="b.php" method="post" name="form1">
<p>
<h3 class='b'>
Nama : <input class='highlight' placeholder="Nama kamu siapa ?" required="required" type="text" name="nama" size ="30" value="<?php echo $nama ?>"/></h3>
</p>
<p>
<h3 class='b'>
Pastikan Jenis Kelamin ada : <br>
<input type="radio" name="gender" value="L"
<?php ($gender=="L")? print 'checked=""' : print ''; ?>/>
Laki-Laki<br>
<input type="radio" name="gender" value="P"
<?php ($gender=="P")? print 'checked=""' : print ''; ?>/>
Perempuan
</h3>
</p>
<center><input type="submit" name="submit" value="Masuk"></center>
</form>
</body>
</html>
6. That way, the a.php as web validator is complete.
Now it makes b.php webpage, and here are the steps.
1. Create a new php web page, give it a name that will be web b.php converter combination.
2. Fill in the following code above the html code, to set the global variables php program, the decimal input and conversion options.
<?php
if(isset($_POST['submit1'])){
$decimal=$_REQUEST['decimal'];
if(isset($_POST['pilih'])){
$pilih=$_REQUEST['pilih'];
}
else{
$pilih='';
}
}
else{
$decimal='';
$pilih='';
}
?>
3. Next enter the following code, the display manager (css) from b.php.
<html>
<head>
<style type="text/css">
body{
background:url('windows-7-wallpaper.jpg');
}
.ab{
font-family: Gill Sans MT;
padding-top: 5%;
padding-left: 65%;
padding-right: 5%;
color: orange;
text-align: center;
}
.abc{
font-family: Gill Sans MT;
padding-top: 1%;
padding-left: 65%;
padding-right: 5%;
color: orange;
text-align: center;
}
a {
font:18px;
font-weight: bold;
color: white;
text-align: center;
padding: 10px;
border-radius: 12px;
-webkit-border-radius: 12px;
background: lightblue;
}
a:hover{
background: orange;
}
a:active{
color: #990000;
}
form {
padding-bottom: 0%;
padding-left: 65%;
padding-right: 5%;
}
.b{
color: lightgreen;
}
.bayangan1{
font-family:Calibri;
font-weight:bold;
color:blue;
}
form input.highlight{
background: aquamarine;
border-radius:5px;
padding: 5px;
}
form input.highlight:focus {
border: solid 1px #D9AD00;
border-radius:5px;
box-shadow:2px 2px 5px blue;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<h1 class="ab">
Selamat Datang di Tempat Konversi Bilangan</h1>
<table border="0" width="900px" heigh="900px" align ="center">
<tr>
<td class="abc">
<!-- Proses Pilih Gender dari file Validator.php -->
<?php
if(isset ($_POST['submit'])){
$nama=$_REQUEST['nama'];
if(isset($_POST['gender'])){
$gender=$_REQUEST['gender'];
}
else{
$gender='';
}
}
if(isset ($_POST['submit'])){
if($nama==''|| $gender==''){// tanda || : OR
echo"<script>
alert('Maaf data kurang lengkap ? Isi Nama dan Jenis Kelamin');
document.location.href='a.php';
</script>";//menggunakan javascript
}
else{
//cek jenis kelamin
//yang ini pakek petik dua
if($gender=='L'){
echo"<br><h1>
Selamat Datang abang $nama !!</h1>
";
}
else{
echo"<br><h1>
Selamat Datang nona $nama !!</h1>
";
}
}
}
?>
<!-- End proses pilih Gender -->
</td>
</tr>
</table>
5. After that, insert the following code to set the look and function of the converter combination.
<table border="0" width="900px" heigh="900px" align ="center" class='bayangan1'>
<tr>
<td align ="center">
<p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>
"
method="POST" name="form1">
<h2>
Tuliskan nilai bilangan Desimal nya : </h2>
<input class='highlight' placeholder="Masukkan Bilangan Desimal disini" required="required" type="text" name="decimal" size ="25" value="<?php echo $decimal ?>"/><br>
<h2>
Mau Convert ke ?? <br>
<input type="radio" name="pilih" value="B"
<?php ($pilih=="B")? print 'checked=""' : print ''; ?>/>
Biner<br>
<input type="radio" name="pilih" value="H"
<?php ($pilih=="H")? print 'checked=""' : print ''; ?>/>
Hexa<br>
<input type="radio" name="pilih" value="O"
<?php ($pilih=="O")? print 'checked=""' : print ''; ?>/>
Oktal<br>
</h2>
<input type="submit" name="submit1" value="Convert"><br>
</form>
<!-- Proses Konversi -->
<?php
if(isset($_POST['submit1'])){//isset : penekanan form
$decimal=$_REQUEST['decimal'];
if(isset($_POST['pilih'])){
$pilih=$_REQUEST['pilih'];
}
else{
$pilih='';
}
}
else{
$decimal='';
$pilih='';
}
if(isset ($_POST['submit1'])){
if($decimal==''|| $pilih==''){
echo"<script>alert('Silahkan pilih dahulu konversi apa yang akan anda lakukan..')</script>";//menggunakan javascript
}
else{
if($pilih=='B'){
//Konversi ke Biner
if (isset($_POST['decimal'])) {
$decimal = $_POST['decimal'];
$original = $_POST['decimal'];
$binary = '';
if (preg_match('/[^0-9]/',$decimal)) {
die ("Yang anda inputkan salah, seharusnya anda menginputkan bilangan desimal saja..");
}
else {
while ($decimal > 0) {
if ($decimal%2 == 0) {
$binary .= 0;
$decimal /= 2;
}
else {
$binary .= 1;
$decimal = ($decimal/2)-0.5;
}
}
$result = strrev($binary);
echo "<br><h2>
Bilangan decimal : $original jika dijadikan Biner hasilnya adalah $result.</h2>
";
}
}
else {
}
}
else{
if($pilih=='H'){
//Konversi ke Hexa
if(isset($_POST['decimal'])){
$des=$_POST['decimal'];
$original=$_POST['decimal'];
$hex='';
while ($des>0){
$hasil=$des%16;
switch($hasil){
case 0 : $hex.="0"; break;
case 1 : $hex.="1"; break;
case 2 : $hex.="2"; break;
case 3 : $hex.="3"; break;
case 4 : $hex.="4"; break;
case 5 : $hex.="5"; break;
case 6 : $hex.="6"; break;
case 7 : $hex.="7"; break;
case 8 : $hex.="8"; break;
case 9 : $hex.="9"; break;
case 10: $hex.="A"; break;
case 11: $hex.="B"; break;
case 12: $hex.="C"; break;
case 13: $hex.="D"; break;
case 14: $hex.="E"; break;
case 15: $hex.="F";
default:break;
}
if($des/16==0){
$sisa=($des%16);
$des=$sisa;
}
else{
$sisa=($des/16);
$des=$sisa%16;
}}
$result = strrev($hex);
echo "<br><h2>
Bilangan decimal : $original jika dijadikan Hexadecimal hasilnya adalah $result.</h2>
";
}
}
else{
//Konversi ke Oktal
if(isset($_POST['decimal'])){
$des=$_POST['decimal'];
$original=$_POST['decimal'];
$octal='';
while ($des>0){
$hasil=$des%8;
switch($hasil){
case 0 : $octal.="0"; break;
case 1 : $octal.="1"; break;
case 2 : $octal.="2"; break;
case 3 : $octal.="3"; break;
case 4 : $octal.="4"; break;
case 5 : $octal.="5"; break;
case 6 : $octal.="6"; break;
case 7 : $octal.="7";
default:break;
}
if($des/8>0){
$sisa=($des/8);
$des=$sisa%8;
}
else{
$sisa=($des%8);
$des=$sisa;
}}
$result = strrev($octal);
echo "<br><h2>
Bilangan decimal : $original jika dijadikan Oktal hasilnya adalah $result.</h2>
";
}
else{
}
}
}
}
}
echo "<h2>
<a href='a.php'>RESET</a></h2>";
?>
<!-- End proses Konversi -->
</td>
</tr>
</table>
</body>
</html>
6. After that, restart apache on xampp, and shift +6 a.php program, the results of the program:
Fill in your name and your gender.
then click the login button.
Later the image will appear like this:
Then fed decimal numbers
Click the convert button will appear
Then click reset, try to fill login before the data is not complete, it will display:
It is done, my explanation of the conversion of numbers in php.
Tidak ada komentar:
Posting Komentar