Anda di halaman 1dari 6

1.

TEXT

<!DOCTYPE html>
<html>
<head>
<title> Tugas 1 </title>
</head>
<body>

<?php
echo "<p> <h1 style=color:blue;> Text ini muncul dari dalam kode PHP
</h1> </p> <hr>"
?>
<br>
<p>Text ini dari HTML</p>
<hr>

</body>
</html>
2. Variabel dan Konstanta

<!DOCTYPE html>
<html>
<head>
<title> Tugas 2 </title>
</head>
<body>

<?php
$txt = "Teks ini adalah isi dari variabel judul = Pemrograman Web dan
Perangkat Bergerak";
$x = "Teks ini adalah isi dari variabel harga = 80000";
$y = "Teks ini adalah isi dari Konstanta + 20000 = 100000";

echo $txt;
echo "<br>";
echo $x;
echo "<br>";
echo $y;
?>

</body>
</html>
3. Operator

<!DOCTYPE html>
<html>
<head>
<title> Tugas 3 </title>
</head>
<body>
<?php
$a=5;
$b=$a+3;
$c=$a+$b;
$d=$a+$b*$c;
$e=($a+$b)*$c;
$f=$c/$b;
$g=$c%$b;
echo $a;
echo "<br>".$b;
echo "<br>".$c;
echo "<br>".$d;
echo "<br>".$e;
echo "<br>".$f;
echo "<br>".$g;
?>
</body>
</html>
4. Pemilihan

<!DOCTYPE html>
<html>
<head>
<title>Tugas 4</title>
</head>
<body>
<form action="index.php" method="POST">
PROGRAM CEK <br>
Nilai1 : <input type="text" name="x">
Nilai2 : <input type="text" name="y">
<input type="submit" value="Hasil">
</form>
<?php
if ($_POST) {
$x = $_POST['x'];
$y = $_POST['y'];
if ($x > $y) {
echo "NILAI TERBESAR ADALAH ".$x;
}
elseif ($x < $y) {
echo "NILAI TERBESAR ADALAH ".$y;
}
}
?>

</body>
</html>
5. Form

<!DOCTYPE html>
<html>
<head>
<title>Tugas 5</title>
</head>
<body>

<form action="index.php" method="post">


PROGRAM MENAMPILKAN<br>
NAMA : <input type="text" name="nama">
ALAMAT : <textarea name="alamat"></textarea>
<br>
<input type="submit" value="Hasil">
<input type="reset" value="Reset">
</form>
<?php
if($_POST){
$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
echo $nama;
echo "<br>".$alamat;
}
?>
</body>
</html>
6. For

<!DOCTYPE html>
<html>
<head>
<title>Tugas 6</title>
</head>
<body>
<?php
function cetak($a)
{
for ($b=1; $b<=$a; $b=$b+1)
{
echo $b;
echo "keren";
echo "<br>";
}
}
?>
<form name="forminput" active="Tugas 6 soal No 6.php" method="post">
Masukkan sebuah angka:
<input type="text" name="angkanya"><br>
<input type="submit" name="cetak">
<input type="reset" name="batal">
</form>
<hr>
<?php
if (isset($_POST["angkanya"])) {
$x = $_POST["angkanya"];
echo "<hr>";
cetak($x);
}
?>
</body>
</html>

Anda mungkin juga menyukai