Rabu, 06 Januari 2010

PHP : HAPUS KOLOM

$koneksi=mysql_connect("localhost","","") or die ("Koneksi gagal");
$tabel="mahasiswa";
$kolom="id";

$sql="ALTER TABLE $tabel DROP $kolom";
$qry=mysql_db_query("contoh",$sql,$koneksi);

if ($qry) {
print "Kolom telah berhasil di hapus";
} else {
print "Kolom gagal di hapus";
}
mysql_close();
?>

PHP \; HAPUS ARRAY

$awal = array ("satu","dua","tiga","empat","lima");

print "Jumlah elemen data pada array \$awal adalah ". count($awal)."

";

while ($awal)
{
$nilai = array_shift($awal);
array_shift() adalah menghapus array 1/1
print "Di hapus $nilai
";
print "Sekarang ada ".count($awal)." elemen data pada \$awal
";
}
?>

PHP : GMT

$GMT = (7*3600); // perbedaan waktu dengan server misal 7 jam

$hari = array("Minggu","Senin","Selasa","Rabu","Kamis","Jumat","Sabtu");
$bulan = array("Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember");

$tanggal[0]=$hari[date("w", time() + $GMT)];
$tanggal[1]=date("d", time() + $GMT);
$tanggal[2]=date("n", time() + $GMT);
$tanggal[3]=date("Y", time() + $GMT);
$tanggal[4]=date("H", time() + $GMT);
$tanggal[5]=date("i", time() + $GMT);

echo "

";
echo "$tanggal[0], ";
echo "$tanggal[1] ". $bulan[$tanggal[2]]." $tanggal[3]
";
echo "$tanggal[4] : $tanggal[5] WIB
";
echo "

";
?>

PHP : GARIS

header("Content-Type:image/jpeg");
$background=@imagecreate(100,100);
$kuning=imagecolorallocate($background,250,250,300);
$hitam=imagecolorallocate($background,0,0,0);
imageline($background,20,20,80,80,$hitam);
imageJPEG($background);
imagedestroy($background);
?>

PHP : GANTI STRING

$kata1 ="Belajar PHP susah ya";
$ubah = str_replace("susah","mudah",$kata1);
print "Kalimat '$kata1' akan diganti menjadi :

";
print "$ubah";
?>

PHP : GANTI TABEL

$koneksi=mysql_connect("localhost","","") or die ("Koneksi gagal");

$tabel_lama="mahasiswa_baru";
$tabel_baru="mahasiswa";

$sql="ALTER TABLE $tabel_lama RENAME $tabel_baru";
$qry=mysql_db_query("contoh",$sql,$koneksi);

if ($qry) {
print "Nama tabel telah berubah";
} else {
print "Nama tabel gagal berubah";
}
mysql_close();
?>

PHP : GANTI FILE

$file_lama='tes123.php';
$file_baru='maseko.php';

if (rename($file_lama,$file_baru)) {
print "Nama file $file_lama sudah sukses di rubah menjadi $file_baru";
}
else {
print "Nama file gagal di rubah";
}
?>

PHP: GANDA

print "Kota Bandung di kenal sebagai \" kota kembang \" ";
?>

menampilkan tanda petik ganda \"

PHP : GABUNG ARRAY

$pertama = array ("satu","dua","tiga");
$kedua = array ("empat","lima","enam");
$ketiga = array ("tujuh","delapan","sembilan");

$gabung = array_merge($pertama,$kedua,$ketiga);

print "Contoh menggabung array
";
foreach ($gabung as $nilai)
{
print "$nilai
";
}
?>

PHP : FORMAT

$harga_sepatu = 195450;
print ($harga_sepatu . "\n");
print ("\$" . number_format($harga_sepatu, "2", ".", "") . "\n");
print "
";
print "Harga sepeda motor adalah : ".number_format("12156688","2",",","."). " (dalam rupiah)";
?>

PHP : FORM

print "
Form Masukan Data

";
print "
";
print "";
print "
NIK:";
print "
Nama:";
print "
Alamat:";
print "
Phone:";
print "
Tanggal Masuk:";
print "
Bagian:";
print "
Jabatan:";
print "
Keterangan:";
print "
";
print "
";
print "
";
?>

PHP ; FOREIGT

$klub = array ("Persik Kediri", "Persebaya Surabaya", "PSIS Semarang", "Persipura Jayapura");

print "Klub-klub yang pernah juara Liga Indonesia :
";

foreach ($klub as $nilai)
{
print "$nilai
";
}
?>

untuk data ratusan
foreach(namaarray as nilai)

PHP ; FOR

for ($i = 1; $i <= 5; $i++) {
print $i ."
";
}

$bila = 5;
$pola = 1;

print "
Bilangan ganjil antara 5 sampai 25
";
for ($pola=1; $pola<10; $pola++)
{
$bila += 2;
print "$bila
";
}

?>

Senin, 04 Januari 2010

PHP : FONT

header ("Content-type: image/png");

$im = ImageCreate (300, 40);
$grey = ImageColorAllocate ($im, 230, 230, 230);
$hitam = ImageColorAllocate ($im, 0, 0, 0);

/* ImageTTFText($im, 20, 0, 10, 25, $hitam, "ARIALBD.TTF", "Pemrograman PHP")."
.";
ImageTTFText($im, 20, 0, 10, 25, $hitam, "TIMES.TTF", "Pemrograman PHP");
ImageTTFText($im, 20, 0, 10, 25, $hitam, "GEORGIA.TTF", "Pemrograman PHP");
ImageTTFText($im, 20, 0, 10, 25, $hitam, "comic.TTF", "Pemrograman PHP");
ImageTTFText($im, 20, 0, 10, 25, $hitam, "COUR.TTF", "Pemrograman PHP");
ImageTTFText($im, 20, 0, 10, 25, $hitam, "lsans.TTF", "Pemrograman PHP");
ImageTTFText($im, 20, 0, 10, 25, $hitam, "TAHOMA.TTF", "Pemrograman PHP");
ImageTTFText($im, 20, 0, 10, 25, $hitam, "TREBUC.TTF", "Pemrograman PHP");
ImageTTFText($im, 20, 0, 10, 25, $hitam, "VERDANA.TTF", "Pemrograman PHP");
*/
ImageTTFText($im, 20, 0, 10, 25, $hitam, "MTCORSVA.TTF", "Tips Pemrograman PHP");

Imagepng ($im);
ImageDestroy ($im);
?>

PHP : EXPLODE

$baru = "Marilah , kita bersatu, untuk maju";
print "Kalimat \$baru = '$baru' diubah menjadi bentuk array menjadi :
";
$pisahkan = explode(",",$baru);
foreach ($pisahkan as $kata1 => $kata2)
{
print "indeks [$kata1] : $kata2
";
}
?>

PHP : EDIT DATA

include_once("konek_db.php");
$sql="select * from karyawan where NIK='$nik'";
$qry=mysql_db_query("karyawan",$sql,$connect);
$row=mysql_fetch_array($qry);

print "
";
print "
Proses Edit Data

";
print "";
print "
NIK:";
print "
Nama:";
print "
Alamat:";
print "
Phone:";
print "
Tanggal Masuk:";
print "
Bagian:";
print "
Jabatan:";
print "
Keterangan:";
print "
";
print "
";
print "
";
?>

PHP : DOWNLOAD

$dir = "D:/xampplite/htdocs/up_download";

if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "file: $file
";
}
closedir ($dh);
}
}
?>

PHP : DETEKSI

function deteksi_IE()
{
if (isset($_SERVER['HTTP_USER_AGENT']) &&
(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
return true;
else
return false;
}

if (deteksi_IE())
{
echo "Anda menggunakan browser Internet Explorer";
} else {
echo "Anda tidak menggunakan browser Internet Explorer";
}
?>

PHP : DAFTAR SESS

session_start();
session_register("nama");
$nama='eko';
print "Nama variabel sessi adalah \$nama
";
print "Isinya adalah $_SESSION[nama]
";


session_start();
session_unregister("nama");
print "session yang ada adalah $_SESSION[nama]";

?>

PHP : COUNTER

$cfile = "datapengunjung.dat";
$fh = fopen($cfile, "r+");

if (!$fh){
die("
Gagal membuka file $cfile.");
}
$s = fgets($fh, 6);

$hitung = (int) $s;
$hitung = $hitung + 1;
$hitung = str_pad($hitung, 6);

rewind($fh);
fwrite($fh, $hitung);

echo "Anda pengunjung ke $hitung";

fclose($fh);
?>

PHP : CEKBOX

print "
";
print "Pilih salah satu makanan yang disukai :
";
print "";
print "Soto
";
print "Bakso
";
print "Sate
";
print "";
print "
";


if ($submit)
{
if (empty($makanan))
{
print "Silahkan pilih salah satu jenis makanan ";
}
else
{
print "Makanan kesukaan Anda adalah $makanan";
}
}
?>

PHP : CEK REKENING

if (ereg("[0-9]{13}",$reke)) {
print "Nomor rekening Anda valid";
} else {
print "Nomor rekening Anda tidak valid";
}
?>

PHP : CEK FORM

print "
";
print "Nama :
";
print "Alamat :
";
print "Pesan :
";
print "";
print "
";

if ($submit) {
if (empty($nama)) {
print "Data Nama belum lengkap.
";
}
elseif (empty($alam)) {
print "Data Alamat belum lengkap.
";
}
elseif (empty($pesan)) {
print "Data Pesan belum di isi
";
}
else {
print "Anda telah mengisi semua data dengan lengkap.
";
}
}
?>

PHP : CEK DATA

if (ereg("[a-z]|[A-Z]","$nama")) {
print "Data Nama Anda valid
";
}
else {
print "Data Nama tidak valid
";
}

if (ereg("[0-9]","$umur")) {
print "Data Umur Anda valid
";
}
else {
print "Data Umur tidak valid
";
}

if (!ereg("^.+@.+\\..+$",$email)) {
print "Email Anda salah, periksa lagi!
";
}
else {
print "Email Anda valid, terimakasih
";
}
?>

PHP : CEK GRAFIS

if (function_exists('imagetypes'))
{
print "modul GD aktif";
}
else
{
print "modul GD belum aktif";
}
?>

PHP : CARI DATA

print "
";
print "Kata yang akan dicari :
";
print "
";
print "Berdasarkan
";
print "NIK
";
print "Nama
";
print "";
print "
";
?>

PHP: CARI FILE

print "
";
print "Cari file
";
print "File : ";
print "
";
print "";
print "
";
?>

PHP : BUAT AKSES

session_start();
?>


print "Session Anda adalah ".session_id();
?>



lihat php.ini

PHP : BUAT DIR

$folder="D:\folder_eko";
if (mkdir($folder,0700)) {
print "Folder $folder telah sukses terbentuk";
} else {
print "Folder $folder gagal terbentuk";
}
?>

PHP : BUAT COOKIE

setcookie("test","Bakso",time()+30);
?>


if (isset($test)) {
print "Nama cookies : $test";
} else {
print "Kunjungan Anda yang pertama";
}
?>




setcookie(nm cookie, data, lama berlaku)

PHP : BUAT ARRAY

$hari = array ("Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu","Minggu");

print "$hari[1]
";
print "$hari[4]";
?>

PHP ; BROWSER

if (($_SERVER['PHP_AUTH_USER'] != 'eko') || ($_SERVER['PHP_AUTH_PW'] != 'ekoya2007'))
{
header('WWW-Authenticate: Basic Realm="Masukkan Username dan Password"');
header('HTTP/1.0 401 Unauthorized');
} else {
print "Anda masuk halaman utama";
}
?>

PHP : BAR MAKER



/*

The Bar chart generator by Ashish Kasturia (http://www.123ashish.com)
Copyright (C) 2003 Ashish Kasturia (ashish at 123ashish.com)


The Bar chart generator is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.

*/




class Bar
{
var $width = 400;
var $height = 300;
var $bgCol;

var $title = "Bar Graph - 123ashish.com";
var $titleCol;

var $dataValues = array();
var $dataXLabels = array();
var $dataSeriesLabels = array();
var $barCol = array();
var $axesCol;
var $image;

function InitializeColors()
{
$this->bgCol = ImageColorAllocate($this->image, 255, 255, 255);
$this->titleCol = ImageColorAllocate($this->image, 0, 0, 0);

$this->barCol[0] = ImageColorAllocate($this->image, 0, 0, 255);
$this->barCol[1] = ImageColorAllocate($this->image, 0, 255, 0);
$this->barCol[2] = ImageColorAllocate($this->image, 255, 0, 0);
$this->barCol[3] = ImageColorAllocate($this->image, 0, 255, 255);
$this->barCol[4] = ImageColorAllocate($this->image, 255, 0, 255);
$this->barCol[5] = ImageColorAllocate($this->image, 255, 255, 0);
$this->barCol[6] = ImageColorAllocate($this->image, 100, 100, 55);
$this->barCol[7] = ImageColorAllocate($this->image, 55, 100, 100);
$this->barCol[8] = ImageColorAllocate($this->image, 100, 55, 100);

$this->axesCol = ImageColorAllocate($this->image, 200, 200, 200);
}

function Bar()
{
$this->image = ImageCreate($this->width, $this->height);
$this->InitializeColors();
ImageFill($this->image, 0, 0, $this->bgCol);
}

function SetDimensions($width, $height)
{
ImageDestroy($this->image);
$this->height = $height;
$this->width = $width;

$this->image = ImageCreate($this->width, $this->height);
InitializeColors();
ImageFill($this->image, 0, 0, $this->bgCol);
}

function SetBGJPEGImage($file)
{
// SetBGJPEGImage() and SetDimensions() cannot be used together
ImageDestroy($this->image);
$this->image = ImageCreateFromJPEG($file);
$this->width = ImageSX($this->image);
$this->height = ImageSY($this->image);
$this->InitializeColors();
}
function SetBGPngImage($file)
{
// SetBGPngImage() and SetDimensions() cannot be used together
ImageDestroy($this->image);
$this->image = ImageCreateFromPng($file);
$this->width = ImageSX($this->image);
$this->height = ImageSY($this->image);
$this->InitializeColors();
}
function SetBGGifImage($file)
{
// SetBGGifImage() and SetDimensions() cannot be used together
ImageDestroy($this->image);
$this->image = ImageCreateFromGif($file);
$this->width = ImageSX($this->image);
$this->height = ImageSY($this->image);
$this->InitializeColors();
}
function SetBGColor($bgR, $bgG, $bgB)
{
ImageColorDeallocate($this->image, $this->bgCol);
$this->bgCol = ImagecolorAllocate($this->image, $bgR, $bgG, $bgB);
}

function SetTitle($title)
{
$this->title = $title;
}

function SetTitleColor($bgR, $bgG, $bgB)
{
ImageColorDeallocate($this->image, $this->titleCol);
$this->titleCol = ImagecolorAllocate($this->image, $bgR, $bgG, $bgB);
}

function AddValue($xVal, $yVal)
{
// $yVal is an array of y values
$this->dataValues[] = $yVal;
$this->dataXLabels[] = $xVal;
}

function SetSeriesLabels($labels)
{
$this->dataSeriesLabels = $labels;
}

function SetBarColor($bgR, $bgG, $bgB)
{
// ImageColorDeallocate($this->image, $this->barCol);
// $this->barCol = ImagecolorAllocate($this->image, $bgR, $bgG, $bgB);
}

function SetAxesColor($bgR, $bgG, $bgB)
{
ImageColorDeallocate($this->image, $this->axesCol);
$this->axesCol = ImagecolorAllocate($this->image, $bgR, $bgG, $bgB);
}

function spit($type)
{
// spit out the graph

$black = ImageColorAllocate($this->image, 0, 0, 0);

// draw the box
ImageLine($this->image, 0, 0, $this->width - 1, 0, $black);
ImageLine($this->image, $this->width - 1, 0, $this->width - 1, $this->height - 1, $black);
ImageLine($this->image, $this->width - 1, $this->height - 1, 0, $this->height - 1, $black);
ImageLine($this->image, 0, $this->height - 1, 0, 0, $black);

// draw the axes
// Y
for($i = 0; $i <= 4; $i++)
{
$tmpVal = 4 - $i;
$y1 = 40 + (($tmpVal * ($this->height - 80)) / 4);
ImageLine($this->image, 40, $y1, $this->width - 80, $y1, $this->axesCol);
}
// X
ImageLine($this->image, 40, $this->height - 40, 40, 40, $this->axesCol);
ImageLine($this->image, $this->width - 80, $this->height - 40, $this->width - 80, 40, $this->axesCol);

// calculate the max of each range
$tmpArray = Array();
$maxValues = Array();
$numSequences = sizeof($this->dataValues[0]);

for($i = 0; $i < $numSequences; $i++)
{
$tmpArray[$i] = Array();
for($j = 0; $j < sizeof($this->dataValues); $j++)
{
$tmpArray[$i][] = $this->dataValues[$j][$i];
}
}

for($i = 0; $i < $numSequences; $i++)
{
$maxValues[$i] = max($tmpArray[$i]);
}

// put the y axis values
for($i = 0; $i <= 4; $i++)
{
$tmpVal = 4 - $i;
$y1 = 40 + (($i * ($this->height - 80)) / 4);

for($j = 0; $j < $numSequences; $j++)
{
$str = sprintf("%.2f", ($maxValues[$j] * (4 - $i) / 4));
$strHeight = ImageFontHeight(2);
ImageString($this->image, 2, 5, $y1 + (($j - $numSequences / 2) * $strHeight), $str, $this->barCol[$j % 9]);
}
}

// put the title
$titleWidth = ImageFontWidth(3) * strlen($this->title);
ImageString($this->image, 3, ($this->width - $titleWidth) / 2, 10, $this->title, $this->titleCol);

// put the series legend
$legendWidth = ImageFontWidth(3) * strlen("Legend");
ImageString($this->image, 3, $this->width - $legendWidth - 5, 40, "Legend", $this->titleCol);
for($i = 0; $i < sizeof($this->dataSeriesLabels); $i++)
{
$legendWidth = ImageFontWidth(3) * strlen($this->dataSeriesLabels[$i]);
ImageString($this->image, 3, $this->width - $legendWidth - 5, 60 + $i * ImageFontWidth(2) * 2, $this->dataSeriesLabels[$i], $this->barCol[$i % 9]);
}

// divide the area for the values
$xUnit = ($this->width - 120) / sizeof($this->dataValues);

// finally draw the graphs
for($i = 0; $i < sizeof($this->dataValues); $i++)
{
$labelWidth = ImageFontWidth(1) * strlen($this->dataXLabels[$i]);
$labelHeight = ImageFontHeight(1);

ImageString($this->image, 1,
40 + $xUnit * ($i + 0.5) - $labelWidth / 2,
$this->height - 35 + ($i % 2) * $labelHeight,
$this->dataXLabels[$i], $this->titleCol);
$x1Unit = ($xUnit - 10) / sizeof($this->dataValues[$i]);

for($j = 0; $j < sizeof($this->dataValues[$i]); $j++)
{
$x1 = 40 + ($xUnit * $i) + 5 + ($x1Unit * $j);
$x2 = 40 + ($xUnit * $i) + 5 + ($x1Unit * ($j + 1));

// $maxValues[$j] corresponds to $this->height - 80
$tmpVal = $maxValues[$j] - $this->dataValues[$i][$j];
// $tmpVal corresponds to ($tmpVal * ($this->height - 80)) / $maxValues[$j];
$y1 = 40 + (($tmpVal * ($this->height - 80)) / $maxValues[$j]);
$y2 = $this->height - 40;
ImageFilledRectangle($this->image, $x1, $y1, $x2, $y2, $this->barCol[$j % 9]);
}
}

if($type == "jpg")
{
Header("Content-type: image/jpeg");
ImageJpeg($this->image);
}
if($type == "png")
{
Header("Content-type: image/png");
ImagePng($this->image);
}
if($type == "gif")
{
Header("Content-type: image/gif");
ImageGif($this->image);
}

ImageDestroy($this->image);

}
}


?>

PHP : BAR EXMP 2



/*

The Bar chart generator by Ashish Kasturia (http://www.123ashish.com)
Copyright (C) 2003 Ashish Kasturia (ashish at 123ashish.com)


The Bar chart generator is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.

*/




include("barmaker.php");

$b = new Bar();

$b->SetBGJPEGImage("../model.jpg");
$b->SetTitleColor(245, 245, 255);
$b->SetTitle("Catherine's shopping list!");
$b->AddValue("Day 1", array(2, 4, 2));
$b->AddValue("Day 2", array(3, 10, 3));
$b->AddValue("Day 3", array(1, 7, 4));
$b->SetSeriesLabels(Array("Cakes", "Candies", "Ice creams"));

$b->spit("jpg");


?>

PHP : BAR EXAMPLE



/*

The Bar chart generator by Ashish Kasturia (http://www.123ashish.com)
Copyright (C) 2003 Ashish Kasturia (ashish at 123ashish.com)


The Bar chart generator is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.

*/




include("barmaker.php");

$b = new Bar();

//$b->SetBGJPEGImage("../model.jpg");
$b->SetTitleColor(245, 245, 255);
$b->SetTitle("Weekly Motorbike Sales");
$b->AddValue("Sunday", array(20, 55, 22));
$b->AddValue("Monday", array(25, 34, 33));
$b->AddValue("Tuesday", array(66, 24, 44));
$b->AddValue("Wednesday", array(70, 77, 10));
$b->AddValue("Thursday", array(56, 25, 56));
$b->AddValue("Friday", array(34, 0, 88));
$b->AddValue("Saturday", array(56, 78, 66));
$b->SetSeriesLabels(Array("Model 1", "Model 2", "Model 3"));

$b->spit("jpg");


?>

PHP : BACA

$dir = opendir("./");

while ($baca_file = readdir($dir))
{
echo "$baca_file", "\n";
}
closedir($dir);
?>

PHP : ASIGNMENT

$data1=10; mengisi nilai sebelah kiri operator dgn hasil nilai yg ada sebelah kanan operator
$data1+=2; menambah nilai yg ada sbelah kanan operator ke var sebelah kiri dan hasilnya disimpan di var itu.
print "Nilai \$data1 adalah $data1

";

$data2=10;
$data2-=5; mengurangi nila sbelah kanan opr ke var belah kiri dan hailnya disimpan juga
print "Nilai \$data2 adalah $data2

";

$data3=10;
$data3*=4; mengalikan milai yg ada sbelah kanan opr ke var kiri dan disimpan di var tsb
print "Nilai \$data3 adalah $data3

";

$data4=20;
$data4/=5; membagi milai yg ada sbelah kanan opr ke var kiri dan disimpan di var tsb
print "Nilai \$data4 adalah $data4

";

$data5=12;
$data5%=7; mengalikan milai yg ada sbelah kanan opr ke var kiri dan sisa pembaginya disimpan di var tsb
print "Nilai \$data5 adalah $data5";
?>

PHP : ARAY KE STRING

$kalimat = "Bersatu kita teguh bercerai kita runtuh";
print "Variabel string \$kalimat = '$kalimat' , di ubah menjadi data array menjadi
";
$pisah = explode(" ",$kalimat);
foreach ($pisah as $indeks => $tampil)
{
print "indeks [$indeks] : $tampil
";
}
print "
";
print "Diubah lagi menjadi data string yaitu
";
$ubah = implode(" ",$pisah);
print "$ubah";
?>


explode(jenis pemisah,datastring,jumlah elemen)
string menjadi array
implode(tanda penggabung,nm array)

PHP : ARITMATIKA

$nilai1=32;
$nilai2=8;

$jumlah=$nilai1+$nilai2;
$kurang=$nilai1-$nilai2;
$kali=$nilai1*$nilai2;
$bagi=$nilai1/$nilai2;
$sisa=$nilai1%$nilai2;

print "Contoh operasi Aritmatika
";
print "Nilai \$nilai1=$nilai1 dan \$nilai2=$nilai2

";
print "\$nilai1 + \$nilai2 = $jumlah
";
print "\$nilai1 - \$nilai2 = $kurang
";
print "\$nilai1 * \$nilai2 = $kali
";
print "\$nilai1 / \$nilai2 = $bagi
";
print "\$nilai1 % \$nilai2 = $sisa
";
?>


simbol + = penjumlahan
% = sisa pembagian

PHP : AKUISISI

$date_array = getdate();
foreach ( $date_array as $key => $val ){
print "$key = $val
";
}
print "
";
print "Hari ini: $date_array[mday]-$date_array[mon]-$date_array[year]

";
?>

PHP : AKSES SERVER

print "Informasi tentang Server Anda
";
print "Server : ". $SERVER_SOFTWARE ."
";
print "Nama server : ".$SERVER_NAME ."
";
print "Nama protokol yang digunakan : ".$SERVER_PROTOCOL ."
";
print "Lokasi direktori skrip ini : ".$DOCUMENT_ROOT ."
";
print "Nama skrip ini adalah : $PHP_SELF
";
print "Port yang digunakan : ".$SERVER_PORT ."
";
?>

PHP : ACAK ARRAY

$angka = array ("a" => "12","d" => "22","b" => "34","c" => "67");

print "Data sebelum di acak =
";
foreach ($angka as $tampil => $tampil1)
{
print "$tampil : $tampil1
";
}

print "Data setelah diacak =
";
shuffle($angka);
foreach ($angka as $tampil => $tampil1)
{
print "$tampil : $tampil1
";
}
?>

ACAK ARRAY 1 PHP

$nama = array ("Budi","Doni","Joko","Dewi","Yuli");

print "Data array adalah :
";
foreach ($nama as $tampil)
{
print "$tampil
";
}
print "Data diambil dua secara acak yaitu :
";
$ambil = array_rand($nama,2);

print $nama[$ambil[0]]. "
";
print $nama[$ambil[1]];
?>

PHP : Memberi Nilai pada variabel

$nilai1=12; //tipe data integer
$nilai2=8.99; //tipe data float atau double
$nilai3= "Tes nilai variabel string"; //tipe data string

print "Tipe data integer : $nilai1
";
print "Tipe data double : $nilai2
";
print "Tipe data string : $nilai3 ";
?>

$namavariabel=nilai data