PHP Lesson: Basic Syntax

 Basic PHP Syntax

<!DOCTYPE html>
<html>
<body>

<h1>My first PHP page</h1>

<?php
echo "Hello World!";
?>

</body>
</html>

Comments in PHP

<?php
// This is a single-line comment

# This is also a single-line comment

/*
This is a multiple-lines comment block
that spans over multiple
lines
*/

// You can also use comments to leave out parts of a code line
$x = 5 /* + 15 */ + 5;
echo $x;
?>

 Creating (Declaring) PHP Variables

<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>

The PHP echo Statement

<?php
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
$cars = array("Volvo", "BMW", "Toyota");

echo "<h2>PHP is fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This", " string", " was", " made", " with multiple parameters.";

echo $txt1 . "<br>";
echo "Study PHP at " . $txt2 . "<br>";
echo "My car is a " . $cars[0];
?>

Penerangan lanjut di

  1. http://www.w3schools.com/php/php_syntax.asp
  2. http://www.w3schools.com/php/php_variables.asp
  3. http://www.w3schools.com/php/php_echo_print.asp

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.