Tutorial Pemrograman PHP, Contoh Program PHP

Banner 468

Facebook
RSS

Variabel PHP

-
Unknown

Variable pada PHP direpresentasikan oleh karakter dollar ($) dan dilanjutkan dengan nama variable tersebut. Variable pada PHP bersifat case-sensitive. Nama variable yang valid pada php dimulai dengan huruf atau underscore (_) dan diikuti oleh huruf, angka atau underscore. Jika dilihat sebagai regular expression:

[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*

Huruf terdiri dari a sampai z dan A sampai Z, karakter ASCII dari 127 sampai 255 (0x7f sampai 0xff). Variable tidak boleh menggunakan tanda baca ataupun reserved word PHP, seperti print, echo.
Contoh :
<?php
$a="5";
$b="2.5";
$komentar="Selamat Datang di PHP";
echo ("Nilai variabel a adalah = $a <br>");
//variabel bertipe integer
echo ("Nilai variabel b adalah = $b <br>");
//variabel bertipe real
echo ("Nilai variabel komentar adalah = $komentar<br>");
//variabel bertipe string
$hasil=$a+$b;
echo ("Hasil jumlah a dan b adalah = $hasil <br>"); //variabel bertipe double
$tgl = date("d F Y"); //variabel bertipe tanggal
$nama = "Politeknik Telkom";
$garis= "=====================================";
echo "<p>";
echo $garis."<br>";
echo $komentar. " Di Lab ". $nama. "<br>Belajar dengan giat
ya.... <br>";
echo $garis."<br>";
echo "Tanggal ".$tgl;
?>

3 Responses so far.

  1. wah ribet sekali kayaknya bro regexnya..
    mungkin bisa dipersimpel
    salam




    http://bayu-immanuel.blogspot.com/

  2. Unknown says:

    mas dikasih tampilan contoh dunk biyar lebih bisa dipahami???

  3. The casino is over. Let's say you're going to die in the casino
    “There is a whole 동해 출장마사지 lot of excitement on your horizon,” says Wynn Resorts CEO Matt Maddox, 하남 출장마사지 as 오산 출장샵 he 광양 출장샵 walks through 경상북도 출장안마 the property,

Leave a Reply