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

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.


Warning: mysqli_fetch_array() expects pa...
HTML div style property...
CSS bold, Style, Property...
CSS background image size to fit screen ...
PHP convert array to string with commas...
PHP array to comma separated string with...
How to put text in image HTML...
How to insert text in html code using ja...
PHP array_key_exists() Function...
Bootstrap Templates...
Bootstrap Text...
Bootstrap Accordion...
Bootstrap Scrollspy...
Bootstrap Carousel...
Bootstrap Modal...
Bootstrap Responsive Layout...
Bootstrap Fluid Layout...
Bootstrap Fixed Layout...
Bootstrap Grid...
Bootstrap Input...