Wednesday, 2 May 2012

PHP Basics

1. Familiarity:
PHP is not familiar with any other languages. As most of the languages are familiar with other languages like java and c.

2. Simplicity:
In PHP script we can write 10,000 lines of code or 1 line of code, but our job should be done. There are no need of including libraries or any other sort of things.The code between <? and ?> will compulsorily execute if the syntactically the program is correct.

3. Efficiency:
When we work on any language or write code, we should work with lot of efficiency then only the application of the program works successfully.


4. Security:
PHP provides administrators and developers with a flexible set of security safeguards. These security safeguards are 2 frames that is system level and application level.


Introductory sample program of PHP:



<?
$site_title="PHP Recipes";
$bg_color = "white";
$user_name =" chef Sarala"
?>


<html>
<head>
<title>
<? print $site_title; ?>
</title>
</head>
<body bgcolor= "<? print bg_color ; ?>">
<?
print " PHP Recipes |".date("F d,Y ")." <br> Greetings, $user_name! <br> ";
?>
</body>
</htmll>

out put:


In the output of the program you can observe that the title bar is PHP Recipies which we have included in title tags and in the body of the window you can see PHP Recipes with Date and year which we have included in the body of the program


Downloading PHP Software:
We can download PHP software from the sites available in internet. But most of the people download it from http://www.php.net where recent updates are also available.


Sample Program 2: Dynamic date Insertion



<html>
<head>
<title> PHP Recipes | <? print (date("F,d,")); ?> </title>
</head>
<body>


</body>
</html>

Out Put:
The code is written in title so the title bar contain PHP Recipes with date and year

PHP date() function:

This function format the current dates. 

Sample program 3:

<htmk>
<head>
<title> PHP Recipes | <? print (date("F d,Y")); ?></title>
</head>
<?
$big_font="h3";
?>
<body>
<? print "<$big_font> PHP Recipes </$big_font>";?>
</body>
</html>

OutPut:

Multiple PHP script Embedding:

For the flexibility of building the web applications we can embed several php scrips separately through out the page.

Sample program 4:

<html>
<head>
<title>
<?
print " Another PHP Enabled Page";
$variable = "Hellow World!";
?>
</title>
</head>
<body>
<? 
print $variable ;
?>
</body>
</html>

Output:


Commenting PHP Code:

Commenting in PHP script is for the comfortability to understand the concept and the script.

There are 2 types of commenting in PHP code:
1.Single line commenting
2. Multiline commenting

We will see about the comments and few more topics later

No comments:

Post a Comment