General Syntactic Characteristics of PHP | Keywords Used in PHP | Variables

CSEBLOG100
2
General Syntactic Characteristics of PHP  | Keywords Used in PHP | Run First Program in PHP

General Syntactic Characteristics:

  • PHP code can be embedded in the XHTML document. The code must be enclosed with in <?php and >

  • If the PHP script is stored in some another file and if it needs to be referred then include construct is used. For instance: 
Include("myfile.inc")

  • The Variable names in PHP begin with the $ sign.

Following are some reserved keywords that are used in PHP.

and

Default

false

if

or

this

break

do

For

include

require

true

case

else

foreach

list

return

var

class

elseif

function

new

static

virtual

continue

extends

global

not

switch

while

 

 

 

 

 

xor


  • The Comments in PHP can be #, //, /* ...*/

  • The PHP statements are terminated by semicolon.

Open some suitable text editor like Notepad and type the following code. save your code buy the extension .php.

It is expected that the PHP code must be stored in htdocs folder of Apache.

As I have installed xampp, I have got the directory c:\xampp\htdocs. I have created a folder named php-example inside the htdocs and stored all my PHP documents in that folder.

Hence when I want to get the output of the PHP code I always give the URL.

http://localhost/php-examples/programName.php
The http://localhost refers to the path c:\xampp\htdocs

Example Program

Following is the first example of PHP script

PHP DOCUMENT [FirstCode.php]

<html>
<head>
<title> PHP Demo </title>
</head>
<body>
<?php
   $i=10;
   echo"<h3> Welcome to first PHP Document </h3>";
   echo "The value of variable is = $i";
   ?>
</body>
</html>



Variables:

What is variables?
  • Variables are the entities that are used for storing the values.

  • PHP is a dynamically typed language. 

  • That is PHP has no type declaration. The Value can be assigned to the variable in following manner -
$variable_name=value

  • If the value is not assigned to the variable then by default the value is NULL. The unsigned variables are called unbound variable.

  • If the unbound variable is used in the expression then its NULL value is converted to the value 0. 

Following are some rules that must be followed while using the variables: 

1. The variable must start with letter or underscore_ , but it should not begin with a number. 

2. It consists of alphanumeric characters or underscore. 

3. There should not be space in the name of the variable. 

4. While assigning the values to the variable the variable must start with the $. For example 

$marks=100; 

  • Using the function IsSet the value of the variable can be tested. That means if IsSet($marks) function returns TRUE then that means some value is assigned to the variable marks

  • If the unbound variable gets referenced then the error reporting can be done with the help of a function error_reporting(7). The default error reporting level is 7.


Other Usefull Links:

Installation of PHP On Your Machine? - Click Here

Introduction to PHP - Click Here

PHP echo and print Statements - Click Here

PHP Data Types - Click Here

Tags

Post a Comment

2Comments

Post Your comments,Views and thoughts Here, Give Us Time To Respond Your Queries

Post a Comment