Array
<?PHP
//array
$var = ['Chessa ', 'Dinda ', 'Agis ', 'Tiara '];
for($x=0; $x<count($var); $x++){
echo $var[$x];
}
?>
Fungsi
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
//anonymus function
$jumlah = function($i){
echo (1+$i);
};
$jumlah(50);
?>
</body>
</html>
Callback
<?PHP
//callback function
$nyanyi = function($test){
echo 'La.. lalala lala...<br>';
echo $test;
};
function testsuara ($test, $callback){
echo $test, '<br>';
call_user_func($callback,'Done');
}
testsuara('ehmmm ehmmm', $nyanyi);
?>
Required
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
//include require
require 'Tugas6_HeaderRequire_Ayunda_1306470211.php';
echo 'Halman Utama';
require 'Tugas6_FooterRequire_Ayunda_1306470211.php';
?>
</body>
</html>
Included
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
//include require
include 'Tugas6_HeaderInclude_Ayunda_1306470211.php';
echo 'Halman Utama';
include 'Tugas6_FooterInclude_Ayunda_1306470211.php';
?>
</body>
</html>
Cookies
<?PHP
//NAMA, NILAI, WAKTU EXPIRE
setcookie('namacookie', 'Sari', time()+120);
echo $_COOKIE['namacookie'];
?>
Session
Filehandling
<?PHP
if(isset($_POST['ok'])){
if(file_exist("file.txt")){
$file = fopen("file.txt", "a+");
$text = " " . $_POST['nama'];
fwrite($file, $text);
echo file_gets_contents("file.txt");
fclose($file);
}else{
echo 'File tidak ada';
?>
<form action="Tugas6_FileHandling_Ayunda_1306470211.php" method ="POST">
<input type="text" name="nama">
<input type="submit" name="ok" value="ok">
</form>
Upload
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
if(isset($_POST['SUBMIT'])){
//print_r($_FILES);
$nama = $_FILES['file']['name'] ;
echo $_FILES['file']['size'] . "<br>";
echo $_FILES['file']['error'] . "<br>";
$asal = $_FILES['file']['tmp_name'] ;
move_uploaded_file ($asal,"upload/".$nama);
}
?>
<form action="Tugas6_Upload_Ayunda_1306470211.php"
method ="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" name="submit" value="upload">
</form>
</body>
</html>
Validasi
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
if(isset($_POST['SUBMIT'])){
$nama = $_FILES['file']['name'] ;
$ukuran= $_FILES['file']['size'] ;
$error= $_FILES['file']['error'];
$asal = $_FILES['file']['tmp_name'] ;
$format = pathinfo ($nama, PATHINFO_EXTENTION); //format data
if ($error === 0){
if($ukuran === 50000){
if($format === "jpg"){
echo 'Berhasil upload!' .$ukuran;
move_uploaded_file($asal, "upload/".$nama);
}else{
echo 'harus jpg!';
}
}else{
echo 'file terlalu besar';
}
}else {
echo 'Ada error';
}
}
?>
<form action="Tugas6_Upload_Ayunda_1306470211.php"
method ="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" name="submit" value="upload">
</form>
</body>
</html>