C:/xampp/htdocs/myfolder/ ထဲ save ပြီးlocalhost/myfolder/ ကနေ ဝင်ကြည့်ပါ
<!-- ဒါ HTML --> <h1>Hello</h1> <?php // ဒါ PHP code echo "This is PHP"; ?> <!-- Short echo tag --> <p><?= $name ?></p> <!-- same as: <?php echo $name; ?> -->
<?php နဲ့ ဖွင့်ပြီး ?> နဲ့ ပိတ်ရတယ်?> မထည့်ရ (best practice)
<?php // Variable names always start with $ $name = "Ko Min"; // string $age = 25; // integer $price = 9.99; // float $isLoggedIn = true; // boolean $nothing = null; // null // PHP is case-sensitive for variables! $Name ≠ $name // Variable naming rules $myVar // ✅ camelCase $my_var // ✅ snake_case (PHP convention) $_myVar // ✅ underscore start OK // $1var = "" // ❌ cannot start with number ?>
<?php $name = "Ko Min"; $age = 25; // echo — most common way to output echo "Hello World"; echo $name; echo "Age: " . $age; // . = concatenation echo "Hi, I'm $name"; // Variable inside double quotes echo "Hi, I'm {$name}!"; // With curly braces // print — same but returns 1 print "Hello"; // var_dump — debug output (type + value) var_dump($age); // int(25) var_dump($name); // string(6) "Ko Min" var_dump(true); // bool(true) // print_r — readable output (for arrays) print_r([1, 2, 3]); ?>
| Type | Example | Description |
|---|---|---|
string | "Hello" | Text |
integer | 42 | Whole number |
float | 3.14 | Decimal number |
boolean | true/false | True or false |
array | [1,2,3] | List / map |
null | null | No value |
object | new MyClass() | Class instance |
<?php // Type checking is_string($x) // true/false is_int($x) // true/false is_float($x) // true/false is_bool($x) // true/false is_array($x) // true/false is_null($x) // true/false gettype($x) // "string", "integer", etc. // Type casting (int)"42" // 42 (string)42 // "42" (float)"3.14" // 3.14 (bool)0 // false ?>
<?php // define() — old way define("MAX_SIZE", 100); define("SITE_NAME", "My Website"); // const — modern way (inside class too) const PI = 3.14159; const DB_HOST = "localhost"; // Usage — no $ sign! echo MAX_SIZE; // 100 echo SITE_NAME; // My Website echo PI; // 3.14159 // PHP Built-in Constants echo PHP_VERSION; // "8.2.0" etc echo PHP_EOL; // Line break echo __FILE__; // Current file path echo __LINE__; // Current line number ?>
<?php // Single line comment // This is a comment // # also works # Another comment /* * Multi-line comment * Use for longer explanations */ /** * PHPDoc comment * @param string $name User's name * @return string Greeting message */ function greet(string $name): string { return "Hello, $name!"; } ?>
C:/xampp/htdocs/learn/ folder ထဲမှာ hello.php file ဆောက်ပြီး ဒါ ရိုက်ပါ:
<?php $name = "ကလေး"; $year = date("Y"); // current year ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>My PHP Page</title> </head> <body> <h1>မင်္ဂလာပါ, <?= $name ?>!</h1> <p>ဒီနှစ်က <?= $year ?> ဖြစ်တယ်</p> <p><?php echo "PHP Version: " . PHP_VERSION; ?></p> </body> </html>
Next: PHP Lesson 02 → Conditions →