Internship Training – Session on PHP

Hi,

On Saturday(30-10-2010) Chandrashekar sir handled session on PHP. The session was started by 11.45 AM.

Sir taught us some of the operators in PHP.

1. === operator

This operator is used to compare two arrays.

Ex: <?php

$a = {10, 20, 30};     $c = {10, 20, 30};    $b = {40, 50, 60}

if($a===$c){

print “Two arrays are equal”;

} ?>

2. + operator

This operator is basically used to add two numbers. But it behaves strange based on the value of the variable.

Ex: <?php

$a = “3 Apples”;    $b = “4 Oranges”;    $c = $a + $b;

print $c; ?>

The output of the above example will be 7. This is because if the first letter of a string is a number the + operator will add that numbers in the two strings. This happens since the + operator always looks for numbers.

3. Concatenate(.) operator

If we want to concatenate two strings we can use dot(.) operator.

Ex: $c = $a . $b;

4. strlen() method

This method is used to find the length of the string.

Ex:  $num = 39057345;

print  strlen($num);

In the above example the value of variable $num will be converted to string and the length of the string is printed.

Passing Variables from one php file to another php file

Sir also taught us how to send a PHP variable from one page to another page. There are many ways to do that.

1. Through hyperlink

Ex:         page1.php

<?php

$uname =  “John & Joe”;   $city = “Chennai=North”;

$url = “page2.php?uname=”.urlencode($uname).”$city=”.urlencode($city);

?>

<a href=<?= $url ?>>Go to page2</a>

In the above example the value of $uname and $city will be passed to page2.php on clicking the hyperlink.

page2.php

<?php $name = $_REQUEST[‘uname’];      $city = $_REQUEST[‘city’];

print “name=$name, city=$city”;   ?>

By using the $_REQUEST variable we can get the value in page2.php from page1.php. $_REQUEST is a super global variable.

2. Through Form submit.

Ex: <form method=POST action=page2.php>

Enter your name: <input type=text name=uname> <br><br>

Enter the city: <input type=text name=city> <br><br>

<input type=submit name=Submit>

</form>

In the above example the values typed in the textbox will be passed to page2.php on clicking the submit button.

In the page2.php we can get the values using $_POST since the method of form is specified as POST.

We can also specify GET in method. Then we use $_GET to get the values in page2.php.

Sir taught the difference between the both GET and POST method with nice examples.

Super Global Variables

Sir also taught how the super global variables can be used and how it works with an simple example. In this example sir showed

  1. How the $GET and $POST variables work.
  2. How to set a cookie variable.
  3. How the $_SERVER variable works.
  4. How to set a session variable and how this session variable can be used in another php file. The session variable are lost if the browser is closed.

Wow. Nice explanation.

Sir then explained how a user authentication can be done with an simple example. In this example sir explained how the modal, view and controller can be created and have it as a separate file and how these three things are combined together. That was really a wonderful example.

Sir showed all the examples as live demo. We asked many doubts in the examples and sir clearly clarified all our doubts.

Finally the session was over by 1.45 PM. We learnt many new things in this session and the session was really interesting. Thanks to Chandrashekar sir.

Regards

Ramachandran

About ramachandranv

I am a cool guy.. Always interested to learn new things..
This entry was posted in Uncategorized. Bookmark the permalink.

6 Responses to Internship Training – Session on PHP

  1. PHP is quickly rising to be one of the most preferred web browser programming languages due to its user-friendliness, efficiency, and user control.
    PHP Training Noida

  2. very nice article to read.A lot of information i got to know from this.As popularity of PHP scripting language increasing hope this will help lot.

  3. sir now am doing asp.net.i want internship training

  4. sir many companies are in bangalore.i need combatore companies

Leave a comment