AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

PHP Syntax


PHP Tutorial » PHP Syntax

A PHP script can be placed anywhere in HTML code and starts with: <?php cod php ?> :

Syntax of PHP:
<?php
// PHP code is placed here
?>


my_file.php - The default file extension for PHP files is ".php".

Below, we make an example of a simple PHP file, with a PHP code that uses a function "echo" to output the text "Hello, how are you doing?" on a web page:

Example: a simple PHP file inside HTML code
<!DOCTYPE html>
<html>
<body>

<h1>My first PHP page</h1>

<?php
echo "Hello, how are you doing?";
?>

</body>
</html>
Note: PHP statements end with ";" (semicolon without qutes).


PHP Case-Sensitivity, example


In PHP, keywords as: echo, if, else, while, etc. classes, functions, and user-defined functions are not case-sensitive..

Example: not case-sensitive.
  <!DOCTYPE html>
<html>
<body>

<?php
ECHO "Hello, how are you doing?<br />";
echo "Hello, how are you doing?<br />";
EcHo "Hello, how are you doing?<br />";
?>

</body>
</html>



PHP variable names are case-sensitive


All variable names are case-sensitive.

Example: case-sensitive.
<!DOCTYPE html>
<html>
<body>

<?php
$color = "white";
echo "My big boat is ". $color ."<br />";
echo "My little house ". $COLOR ."<br />";
echo "My little house is ". $coLOR ."<br />";
?>

</body>
</html>


Variable name rules:

In PHP, variables start with the $ sign followed by the variable name;
The name must begin with the "_" character or a letter;
The name CANNOT start with a digit;
The name can contain alphanumeric characters and underscores;
Variable names are case-sensitive ($age is not the same as $AGE, but they are different variables)




php syntax checker, php syntax tree, error unexpected '' expecting '' end of file, if, checker online, best practices
PHP Syntax - php tutorial

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Home
PHP Introduction
PHP Install
PHP Syntax
PHP Variables
PHP Echo and Print
PHP Data Types
PHP String Function
PHP Constants
PHP Operator Types
PHP If Else and Elseif
PHP Switch
PHP While Loops
PHP Loop For Do Foreach
PHP Array
Convert Array to String
PHP Function
PHP GET and POST
PHP Date/Time Functions
PHP Login
PHP Delete Element
PHP eregi_replace()
PHP mysql_query()
PHP Errors to Display
PHP Loop For Do Foreach

PHP forms
PHP Form Example
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Upload Image, display, edit and delete i...
Login Form with Image background...
How to Create an Image with Transparent ...
Portfolio Gallery Website with filtering...
Simple pagination script PHP MySQLi...
Center Image in div...
Image Hover Overlay Fade...
Sticky image / element / div on scroll...
Responsive images...
Create rounded image in HTML CSS...
Add border around image...
Position Text Over an Image HTML CSS res...
Create a Slideshow Images Gallery...
Create a Sticky Sidebar...
Search bar using CSS HTML...
Shrink Navigation Menu on Scroll...
How to Create Accordion HTML Templates...
Dropdown menu in the navigation bar...
Responsive Top Navigation Bar with mobil...
Split horizontal navigation bar...