When writing first php page , we need to remember these few points
1) PHP files should have .php extension. It get executed on the server by the web server and the resulting text is returned to the browser.The browser never get to know the php code,it only receive the html or text from server.If the person views the source code of the file displayed on the browser,it will only contain the html or text
2) php code is written between tags i.e opening and closing limiter.
Opening <?php and closing ?>
There are other shorts tags available but they require special setting in php init file
a)Opening <? and closing ?>
b)Opening <% and closing %>
Opening <?php and closing ?>
There are other shorts tags available but they require special setting in php init file
a)Opening <? and closing ?>
b)Opening <% and closing %>
3) Each statement in your PHP code is ended with a semicolon. Leaving this semicolon off is a common syntax error and when something isn’t working the way you expect it to should be one of the first things you check.
Example
<?php phpinfo(); ?>
Example
<?php phpinfo(); ?>
Even any variable assignment also need the semicolon
4)Whitespace (spaces, tabs and newlines) are ignored in the syntax of PHP. These three examples are completely equivalent:
<?php echo “test”; ?>
<?php
echo “test”;
?>
4)Whitespace (spaces, tabs and newlines) are ignored in the syntax of PHP. These three examples are completely equivalent:
<?php echo “test”; ?>
<?php
echo “test”;
?>
<?php echo “test”; ?>
5) Writing comments in the code is a useful things. It helps in reading and organising the code. As with other programing language,PHP do have comments syntax
Examples
<?php
<?php
/*
This is test code
*/
This is test code
*/
echo “test”;
?>
?>
<?php
//This is test code
echo “test”;
?>
<?php
echo “test”;
?>
<?php
#This is test code
echo “test”;
?>
6) In PHP, all keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are NOT case-sensitive. But all the variable are case sensitive
echo “test”;
?>
6) In PHP, all keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are NOT case-sensitive. But all the variable are case sensitive
Example
echo “a”; is same as Echo “a”;
$col=1; is not same as $COL=1;
echo “a”; is same as Echo “a”;
$col=1; is not same as $COL=1;
The above explain the basic ideas behind PHP. Lets write the first PHP based on this
<html>
<head>
<title>First PHP page</title>
</head>
<body>
<?php
// The below statement echo the statement
echo “This is php information”;
// The below statement is a php function call which return the php version etc
phpinfo();
?>
</body>
</html>
<head>
<title>First PHP page</title>
</head>
<body>
<?php
// The below statement echo the statement
echo “This is php information”;
// The below statement is a php function call which return the php version etc
phpinfo();
?>
</body>
</html>
0 comments:
Post a Comment