«

»

Dec 08

basic php syntax

A PHP script can be placed anywhere in the html document.

A PHP script starts with <?php and ends with ?>

<?php
// PHP code
?>

A PHP script also use the short-open (SGML-style)  tag start with <? and ends with ?>

<?
// PHP code
?>

The default file extension for PHP files is “.php”. But we can also set the php file extension through rewrite url or setting with apache config file. A PHP file normally contains HTML tags, and some PHP scripting code. PHP statement terminate by semicolon (;) .

<!DOCTYPE html>
<html>
<body>

<h1>My first page</h1>

<?php
echo “Hello Inida!”;
?>

</body>
</html>

Comments in PHP

A comment in PHP code is a line that is not read/executed as part of the program. Its only purpose is to be read by someone who is editing the PHP code!

Three ways of commenting in PHP :

<!DOCTYPE html>
<html>
<body>

<?php
// For single line comment

# This is also for single line comment

/*
Multiple lines comment block

*/
?>

</body>
</html>

PHP is whitespace insensitive:

PHP whitespace insensitive means that it almost never matters how many whitespace characters you have in a row.one whitespace character is the same as many such characters.

For Example: 

$seven = 5 + 2; // single spaces

$seven <tab>=<tab2<tab>+<tab>5 ; // spaces and tabs
$eight =
3+
5; // multiple lines

PHP is case sensitive:

In PHP, all user-defined functions, classes, and keywords are case-insensitive.

However; in PHP, all variables are case-sensitive.

For Example:

<!DOCTYPE html>
<html>
<body>

<?php
ECHO “Hello India!<br>”;
echo “Hello India!<br>”;

?>
<?php
$number=15;
echo “Variable number is ” . $number . “<br>”;
echo “Variable number is ” . $NUmber . “<br>”;

?>
</body>
</html>

Output

Hello India!
Hello India!
Variable number is 15
Variable number is

Braces make blocks:

In case loop and condition like (for, foreach, if else). you can write more than one statement enclosing them in a set of curly braces.

if ($flag == true)
{
   print("Good thinking is best for self growth");
   print("lost my power.<br>");
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>