Sie sind auf Seite 1von 3

<?

php for ($i=12; $i<=25; $i+=3) { if ($i >=10 and $i<=15) continue; print("$i <br>"); if($i>=25) break; } echo "Selesai sudah proses looping"; ?>

18 21 24 Selesai sudah proses looping

echo "<br>"; //print '89' echo substr ('123456789', -2); echo "<br>"; //print '45' echo substr ('123456789', 3, -4); echo "<br>"; echo strlen ('Jakarta'); echo "<br>"; echo strlen (substr('123456789', -2)); echo "<br>"; ?>

12 56789 89 45 7 2

<?php $destination = "Amsterdam"; echo "Travelling to $destination <br>"; Travelling to switch ($destination) { Amsterdam case "Las Vegas"; Bring an open mind echo "Bring an extra $500"; break; case "Amsterdam"; echo "Bring an open mind"; break; case "Egypt"; echo "Bring 15 bottles of SPF 50 Sunscreen"; break; case "Carribean Islands"; echo "Bring a swimsuit"; break; default: echo "tidak sesuai dengan nilai"; echo "jadi bisa menuliskan pesan apa aja"; break; } ?> <?php //print '12' echo substr ('123456789', 0, 2); echo "<br>"; //print '56789' echo substr ('123456789', 4);

<?php $tampil1 = date('D, d F Y'); echo "date('D, d F Y') => $tampil1<br><br>"; $tampil2 = date('h : i : s A'); echo "date('h : i : s A') => $tampil2<br><br>"; $tampil3 = date('F dS, y'); echo "date('F dS, y') => $tampil3<br><br>"; $tampil4 = date('z'); echo "date('z') => $tampil4<br><br>"; echo "date('D, d F Y')=>", date('D, d F Y'); ?>

date('D, d F Y') => Fri, 14 June 2013 date('h : i : s A') => 08 : 17 : 23 AM date('F dS, y') => June 14th, 13 date('z') => 164 date('D, d F Y')=>Fri, 14 June 2013

<?php $file = fopen("per5.txt","r"); while(!feof($file)) { echo fgets ($file). "<br>"; } fclose ($file); ?> Membaca file yang ada di per5.txt

<?php $kalimat = "Pemrograman PHP "; $a =15; $b=25; $c=$a+$b; Printf ("Hasil strtoupper : %s <br> ", strtoupper($kalimat)); printf ("Hasil strtolower : %s <br> ", strtolower($kalimat)); printf ("Hasil ucfirst : %s <br> ", ucfirst($kalimat)); printf ("Hasil ucwords : %s <br> ", ucwords($kalimat)); printf ("Aslinya : $kalimat <br>"); printf ("Hasil ltrim : %s <br> ", ltrim($kalimat)); printf ("Hasil rtrim : %s <br> ", rtrim($kalimat)); printf ("Hasil trim : %s <br> ", trim($kalimat)); printf ("Hasil substr : %s <br>", substr($kalimat,4, 4)); printf ("Hasil substr : %s <br>", substr($kalimat,6, -3)); print "$a + $b = $c <br>"; printf ("$a + $b = %d <br> ", $c); ?> <?php $file = fopen("test.txt","w"); echo fputs ($file, "Hello Bro !! , testing"); fclose($file); ?>

<?php $file = fopen("per5.txt","r"); while(!feof($file)) { echo fgets ($file). "<br>"; } Hasil strtoupper : PEMROGRAMAN PHP Hasil strtolower : pemrograman php Hasil ucfirst : Pemrograman PHP Hasil ucwords : Pemrograman PHP Aslinya : Pemrograman PHP Hasil ltrim : Pemrograman PHP Hasil rtrim : Pemrograman PHP Hasil trim : Pemrograman PHP Hasil substr : ogra Hasil substr : raman P 15 + 25 = 40 15 + 25 = 40 fclose ($file); ?> <?php $nama_file="counter.dat"; If (file_exists($nama_file)) { $berkas = fopen($nama_file,"r"); $pencacah = (integer)trim(fgets($berkas, 255)); $pencacah++; Fclose($berkas); } Else { Anda pengunjung ke-2 $pencacah = 1; //Simpan Pencacah $berkas = fopen($nama_file,"w"); fputs($berkas, $pencacah); Fclose($berkas); } //Tulis ke halaman web print("Anda pengunjung ke-$pencacah <br> \n"); ?> <?php $myfile = "per5.txt"; $fh = fopen($myfile, 'a') or die ("can't open file"); $stringData = "Selamat Belajar"; fwrite($fh, $stringData); echo "Data sudah terekam, silahkan cek file per5.txt"; fclose($fh); ?> Data sudah terekam, silahkan cek file per5.txt Membaca file yang ada di per5.txt

22 Menghitung jumlah karakter. File akan di buat bila belum tersedia

<?php $numbers = array(1,2,3,4,5,6); $age = array("mom" => 45, "pop"=>50, "kop"=> 25); $mixed = array ("Hello" => "world" ,2 => "It's two"); echo "numbers[4] = {$numbers[4]} <br>"; echo "My mom's age is {$age['mom']} <br>"; echo "Mixed['hello'] = {$mixed['Hello']} <br>"; echo "Mixed[2] = {$mixed[2]} <br>"; for ($i=0; $i<=5; $i++) { echo "numbers[$i]={$numbers[$i]}<br>"; } ?> <?php $myarray = array(1,2,3,4,5,6); $myarray[2] = array("Hi", "Hello", "Konniciwa", "Apa Kabar"); echo "<pre>"; print_r($myarray); echo "</pre>"; ?> numbers[4] = 5 My mom's age is 45 Mixed['hello'] = world Mixed[2] = It's two numbers[0]=1 numbers[1]=2 numbers[2]=3 numbers[3]=4 numbers[4]=5 numbers[5]=6 Array ( [0] => 1 [1] => 2 [2] => Array ( [0] => Hi [1] => Hello [2] => Konniciwa [3] => Apa Kabar ) [3] => 4 [4] => 5 [5] => 6 )