Getting Started with PHP Syntax


Introduction to PHP Syntax

PHP (Hypertext Preprocessor) is a server-side scripting language designed for web development. Below is a simple example to help you understand the basic syntax and structure of PHP code.

Example: Displaying "Hello, AIT!"

Here’s a basic PHP script that outputs "Hello, AIT!" on the page.

<?php
echo "Hello, AIT!";
?>

Output:

Hello, AIT!

Using Variables in PHP

In PHP, variables are defined with a dollar sign ($) followed by the name of the variable. Below is an example of using variables in PHP.

<?php
$greeting = "Hello";
$name = "Alice";
echo $greeting . ", " . $name . "!";
?>

Output:

Hello, Alice!

PHP variables are case-sensitive, and they must start with a letter or underscore.