LATIHAN PHP

Ricky Hakim Ronaldo
Sep 4, 2018 · 2 min read
  1. Pengertian PHP

Adalah bahasa pemrograman script server-side yang di desain untuk pengembangan web. selain itu php juga di kembangkan untuk pemrograman umum (wikipedia).

2. Jenis data pada PHP

  • Integer
  • float
  • String
  • Boolean
  • Array
  • Objek

Sumber : www.pengertianku.net

3. Contoh Pemrograman PHP

Mencari Kata

<form action=” “ method=”GET”>
<center>
Kalimat <input type=”textbox” name=”input” style=”width: 20%; height: 10%; color: black; background-color: lightgrey; border-radius: 5px”><br><br>
Kata Cari <input type=”text” name=”find” style=”width: 20%; height: 4%; color: black; background-color: lightgrey; border-radius: 5px” placeholder=”Cari”><br><br>
<input type=”submit” name=”submit” value=”Cari” style=”color: white; background-color: black; width: 5%; height: 3%; border-radius: 5px”>
</center>
</form>
<?php
if(isset($_GET[“submit”])) {
$kalimat = $_GET[“input”];
$find = $_GET[“find”];
$temp = explode($find, $kalimat);
$css1 = “<span style = ‘background-color:yellow’>”;
$css2 = “</span>”;
$kal=””;
for ($i=0; $i < count($temp); $i++) {
$kal.=$temp[$i];
if ($i < count($temp)-1) {
# code…
$kal.=$css1;
$kal.=$find;
$kal.=$css2;
}
}
echo $kal;
}
?>

Membuat bintang

<?php

for( $a=10;$a>0 ;$a — )
{
for($b=10;$b>$a;$b — )
{
echo “*”;
}
echo”<br>”;
}

?>

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Dalam praktikum yang telah saya pelajari melalui Asprak maupun otodidak, terdapat beberapa materi yang saya ambil.

Menampilkan inputan berupa bintang dan deretan angka ganjil dan genap.

berikut kode nya :

<html>
<head>
<title>Mencetak Segitiga</title>
</head>
<body>
<form action = "" method="post">
<table>
<tr>
<td>
<label for="input">Masukkan Nilai</label>
</td>
<td>
<input type="text" name="input" id="input">
</td>
<td>
<button type="Submit">Cetak</button>
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['input'])){
$input = $_POST['input'];
for($r=0; $r<=$input; $r++){
for($l=$r; $l<$input; $l++){
echo "*";
}
echo "<br/>";
}
}
function bilangan($input){
$genap = 0;
echo "Bilangan Genap : ";
for($i=1; $i <= $input; $i++){
if($i%2==0){
echo $i." ";
$genap++;
}
}
$ganjil=0;
echo "<br>Bilangan Ganjil : ";
for ($i=0; $i <= $input; $i++){
if ($i%2==1){
echo $i." ";
$ganjil++;
}
}
echo "<br> Jumlah Bilangan Ganjil : ".$ganjil."<br> jumlah bilangan genap : ".$genap;
}
bilangan($input);

Output :

dalam praktik juga di jelaskan fungsi atau perbedaan antara POST dengan GET.

POST = mengirimkan data atau nilai langsung tanpa menampilkannya dalam URL.

GET = mengirimkan data atau nilai dan menampilkannya dalam URL.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade