You are on page 1of 6

Nama: Topan Saputra

NPM: 21100067

Sesi: 21/B

Tugas: PBW

Sesudah codingnya selesai diketik di Visual studio Code atau di Notepad,


lalu Pergi ke local Disk C dan setelah itu pergi ke folder Xampp lalu terdapat
folder lagi yang bernama “htdocs” gunanya untuk menyimpan program yang telah
dibuat, program PHP dibuat di folder htdocs agar bisa dijalankan di website seperti
chrome dan sebagainya. Lalu cara menjalankan program PHP yaitu cari “Xampp-
control” di folder XamPP. Lalu tekan start pada menu Apache dan Mysql, setelah
itu baru pergi ke chrome dan ketik “localhost/sesuai dengan nama file php anda.

 Tampilan Xampp sebelum program dijalankan


1. Contoh 1
 Code
 <html>
 <html>
 <head>
 <title> Contoh Skrip PHP </title>
 </head>
 <body>
 <?php
 echo "Halo Apa Kabar"."<br>";
 echo "Halo Apa Kabar";
 ?>
 </body>
 </html>

 Hasil run

2. Contoh 2
 Code
 <html>
 <head>
 <title> Contoh Skrip PHP </title>
 <body>
 <?php
 $a=3;
 $b=7;
 $a +=5;
 $b = ($c = 11) + 3;
 echo "Nilai Variabel a adalah = $a";
 echo "<br>";
 echo "Nilai Variabel b adalah = $b";
 echo "<br>";
 echo "Nilai Variabel c adalah = $c";
 ?>
 </body>
 </html>

 Hasil run

3. Contoh 3
 Code
 <html>
 <head>
 <title> Contoh Skrip PHP </title>
 <body>
 <?php
 $a=3;
 $b=7;
 $a +=5;
 $b = ($c = 11) + 3;
 echo "Nilai Variabel a adalah = $a";
 echo "<br>";
 echo "Nilai Variabel b adalah = $b";
 echo "<br>";
 echo "Nilai Variabel c adalah = $c";
 ?>
 </body>
 </html>
 Hasil run

4. Contoh 4
 Code
 <html>
 <head>
 <title> Contoh Skrip PHP </title>
 <body>
 <?php
 $nilai = 85;
 $nama = "Amir" ;
 if ($nilai >= 80)
 {
 echo $nama. "Mendapat nilai A";
 }
 elseif ($nilai >= 70)
 {
 echo $nama. "Mendapat nilai B";
 }
 elseif ($nilai >= 60)
 {
 echo $nama. 'Mendapat nilai C';
 }
 else
 {
 echo $nama. "Mendapat nilai D";
 }
 ?>
 </body>
 </html>
 Hasil run

5. Contoh 5
 Code
 <html>
 <head>
 <title>Contoh skrip PHP</title>
 </head>
 <body>
 <form method="post" action="">
 Tanggal Lahir:
 <select name="tanggal">
 <option value="0" selected>Tanggal</option>
 <?php
 for ($i = 1; $i < 32; $i++) {
 echo "<option value='$i'>$i</option>";
 }
 ?>
 </select>
 </form>
 </body>
 </html>

 Hasil run
6. Contoh 6
 Code
 <html>
 <head>
 <title> Contoh Skrip PHP </title>
 </head>
 <body>
 <?php
 $i = 1;
 do
 {
 echo "$i <br>";
 $i++;
 } while($i <= 5);
 ?>
 </body>
 </html>

 Hasil run

You might also like