Basic 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";
?>

Leave a Reply

Related Posts: You may like

Extract Total Number of Image And Missing Alt Attribute using php

How to extract Heading tags using PHP from string

How to remove whitespace from string using php

Remove All Special Characters From String PHP

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Download Instagram Videos & Photos.

Download Now

CURRENCY CONVERTER

Real Time Currency Converter

Convert Now

ROBOST.TXT GEN.

Robots.txt File Creater

Create Now

HTML MINIFIER

Compress yout HTML Code

Minify Now

CSS MINIFIER

Compress yout CSS Code

Minify Now

JAVASCRIPT MINIFIER

Compress yout JavaScript Code

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.