Saturday, 5 May 2012

PHP Basics

Identifier:


The functions, variables and various other user defined object is known as Identifier.
Identifiers must start with a  underscore and letter.


-> Identifier must be case sensitive.
$recipe,$Recipe,$recipE= all these are different from each other.
->Identifier can be lengthy.
->Identifier should not be any keyword of PHP.


Variable:
A variable is a name to which memory is located that contains data for manuplating the complete program.
A variable always starts with the $.



$color
$operating_system
$_some_variable
$model



Variables too have same rules of identifier.



$sentence = "This is a sentence."; // $sentence evaluates to string.
$price = 42.99; // $price evaluates to a floating-point
$weight = 185; // $weight evaluates to an integer.


We can use variable anywhere in the program. Therefore, variable will get accessed wherever it is necessary.
Therefore, the access domain name is Scope.


Variable scope:
Scope can be the range of availability of variable in a program in which it is declared. 

Arrays

Array:


An array is a list of same kind of element.
In PHP array starts from
Single dimensional Index array:
This is the integer subscript which denotes the position of the requested value.
syntax:
$name[Index1];

Example: 



<?
$meat[0] = "chicken";
$meat[1] = "steak";
$meat[2] = "turkey";
print $meat[2];
?>

out put:
turkey

For 3 varieties we have created array in this manner but if there are thousands then what to do. Then we need to use array function.


Array function syntax:
$name=array(Index1,Index2,Index3...Indexn)

Example:
$meat=array("chicken","turkey","steak");

Another manner of assigning values
$meat[]="chicken"
$meat[]="turkey"
$meat[]="steak"

Multidimensional Indexed Array:
Syntax:
$name[Index1][index2][Index3]..[IndexN];

An element of dimensional Indexed array:
$position=$chess_board[5][4];









Thursday, 3 May 2012

Variables and Data types

Actually data types are the back bone of any program.
There are 6 types of data types in PHP:
1. Integers
2.Strings
3.Floating point numbers
4. Arrays
5. Objects
6. Booleans


String Delimters:



\n Newline
\r Carriage return
\t Horizontal tab
\\ Backslash
\$ Dollar sign
\” Double-quotation mark
\[0-7]{1,3} Octal notation regular expression pattern
\x[0-9A-Fa-f]{1,2} Hexadecimal notation regular expression pattern


A double quote string recognizes all the about delimiters but a single quote string recognizes only delimiters "\" and "\\".


Character handling:
String can be accessed character - by - character like sequently indexed array.
$a_b= 10;
$m=ab;


PHP Basics

1. Singleline Comments:


This means single line comment. We can implement these in 2 styles:
# and //
For example:
<html>
<body>
//Printing the message
print "sarala";
#output will be sarala
</body>
</html>


we can even implement singeline comments into multiline comments.
<?
//file: example.php
//author: WJ Gilmore
//date: 4rthmay2012
print " An example with comment";
?>


2. Multiline comments:
some times php provides more script and at that time we need to write multiline comments. So at that time we need to implement comment in C-style manner.
<?
/* Script multi_comment_example.php
purpose : Multiline comment example
author : sarala
date : 4may2012
*/
print "multiline comment can be found at the top of the script";
?>


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

Tuesday, 1 May 2012

Php Basics

Php full form - Hypertext preprocessor


The fact of Php is, we can embed PHP in HTML code.


Primary and simple Syntax of Html: which we use in Php code:
<html>
<title>
</title>
<body>
</body>
</html>

Php syntax:


<? php
?>


Php code embedded with html code:


<html> <title <? print " Hellow World!" ?> </html>


then the out put will be Hellow World! as the title bar of the browser.


There are 5 characteristics for PHP:


1. Familiarity
2. Simplicity
3. Efficiency
4. Security and Flexibility.


Ok we will learn about these tommarow
thank you