PHP Syntax

Basic PHP Syntax

This Article will teach you of very basic syntax of PHP and how to start environment of PHP and show output.

A PHP scripting always starts with . This is the standard code to start php environment. A PHP scripting block can be placed anywhere in the document. On servers can start php environment with <? and end with ?>.

However, for maximum compatibility, we recommend that you use the standard form rather than the shorthand form.

How to start environment of php

1. standard syntax of php

<?php
    echo "This is Standard syntax of PHP Script !";
?>

2. Short tag syntax of php

<?
    echo "This is Short Tag syntax of PHP Script !";
?>

3. ASP-style syntax of php

<%
    echo "This is ASP Style syntax of PHP Script !";
%>

4. HTML script syntax of php

<script language="PHP">
echo "This is HTML Script Style syntax of PHP Script !";
</script>

To use all tags, you will need to set or enable the configuration option in your php.ini file.

A PHP file must have a .php extension.
A PHP file normally contains HTML tags, and some PHP scripting code.
The PHP script is executed on the server, and the plain HTML result is sent to the browser.

Each code line in PHP must end with a semicolon. The semicolon is a separator and is used to distinguish one set of
instructions from another.
There are two basic statements to output text with PHP, one is echo and second is print.
In the example above we have used the echo statement to print the text “This is the syntax of PHP Script”.

Commenting in PHP Code

A comment is the part of a program that exists only for the human reader which can understand about code reading comment if given.
There are two commenting formats in PHP script:

Single-line comments:
They are generally used for short explanations or notes relevant to the local code.
Here we are giving examples of single line comments.

<?php
# This is a single line comment
# This is the second line of the comment
// This is comment style
echo "This is a single line comment !PHPKIDA";
?>

Multi-lines comment:
They are generally used to provide pseudo-code algorithms and need more detailed explanations when necessary.
Here we are giving examples of multiple lines comment:

 <?php
/* This is a comment with multiline
    Writter: PHPKIDA TEAM
    Subject: Multiline comment in PHP
    message: This is a multiline comment script in php, you can this kind of style as well as code to writr multiline comment.
*/
echo "This is a multi line comments";
?>

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Free online tool to download Instagram videos, photos and save Instagram videos, photos to your device. It's free & easy to use.

Download Now

CURRENCY CONVERTER

Our real time currency converter calculator will convert your money based on current values from around the world. It's free & easy to use.

Convert Now

ROBOST.TXT GEN.

Create robots txt file that help search engines to crawling and indexing your site with help of our free online Robots.txt Generator tool.

Create Now

HTML MINIFIER

Free online tool to minify or compress html code and reduce the size of html code in few clicks. It's free & easy to use.

Minify Now

CSS MINIFIER

Free online tool to minify or compress css code and reduce the size of css code in few clicks. It's free & easy to use.

Minify Now

JAVASCRIPT MINIFIER

Free online tool to minify or compress javascript code and reduce the size of javascript code in few clicks. It's free & easy to use.

Minify Now

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.