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

How to remove whitespace from string using php

Remove All Special Characters From String PHP

Redirecting HTTP to HTTPS with PHP

Convert Base64 string to an image file

Tools:

Crypto Currency

PHPKIDA provides free online the best real-time crypto market price, news, predictions, index with graphs & historical data for 2000+ coins including bitcoin, ethereum, & altcoins from major cryptocurrency exchanges.

Visite Tool

Icon Generator

PHPKIDA provides free online icon generator. Our icon generator help you to edit, modify, resize and customize icon for your website and applications. Convert to a shap you like add icon border, you can change icon border color, border size, background color, icon shadow, icons color, icon size in your own way and save it as a png image.

Visite Tool

Youtube Video Downloader

PHPKIDA provides Free online YouTube video downloader to download YouTube videos quickly in MP4, 3GP, and more. Search your video and free fast download youtube videos.

Visite Tool

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.