Download presentation
Presentation is loading. Please wait.
Published byNorman Charles Modified over 8 years ago
1
Click to edit Master subtitle style 03/02/11 Web And Coding Club IIT Bombay PHP (pre hypertext processor) By: Saurabh Goyal Apekshit Sharma
2
03/02/11 What are we going to talk about ? Why do we need php(or any other server scripting )!! Your first php page. Basics of php Syntax Variables Conditional Statements If..else.. switch…case… Arrays
3
03/02/11 Contd…. Loops while do while for Foreach Functions Get and Post Basic Sessions Interaction with Database(MySQL)
4
03/02/11 Why do we need PHP?? Logins i.e checking username password against stored data. File Upload User dependent info. In general, for all kind of server side processing, we need some server side scripting language. PHP in our case!!
5
03/02/11 Your first PHP page <?php echo “DHONDHU JUST CHILL”; ?> Link : http://localhost/ex/ex1.phphttp://localhost/ex/ex1.php
6
03/02/11 PHP Syntax php code block always start with <?php your code goes here ?> In PHP, we use // to make a single-line comment or /* and */ to make a large comment block. <?php //this is a comment /* this is block blab block ends here */ ?>
7
03/02/11 PHP Variables PHP is a Loosely Typed Language You don’t have to declare variable type. You don’t even have to declare the variable. All variables in PHP start with a $ sign symbol. Isn’t it very Simple !!!! No need to worry of type or casting or anything !! Example: $a1 = 1; $a2 = “1”; $float = 10.01; my_val = 5; !!!!!!!!! wrong!!!!!!!!!
8
03/02/11 With power comes responsibility…..
9
03/02/11 Contd…. Now we have $a1 = 1; $a2 = “1”; So, $a3 = $a1.$a2; $a4 = $a1+$a2; $a3 = ? $a4 = ? ……so one needs to be careful
10
03/02/11 Contd….. Naming Rules for Variables A variable name must start with a letter or an underscore "_" A variable name can only contain alpha- numeric characters and underscores (a-z, A-Z, 0-9, and _ ) A variable name should not contain spaces. If a variable name is more than one word, it should be separated with an underscore ($my_string), or with capitalization ($myString) from www.w3schools.com
11
03/02/11 Conditional Statements <?php $d=“Sun”; if ($d=="Fri") echo "Have a nice weekend!"; elseif ($d=="Sun") echo "Have a nice Sunday!"; else echo "Have a nice day!"; ?> from www.w3schools.com Link : http://localhost/ex/ex2.phphttp://localhost/ex/ex2.php
12
03/02/11 PHP Arrays Numeric array A numeric array stores each array element with a numeric index.
13
03/02/11 Contd….. Associative array An associative array, each ID key is associated with a value.
14
03/02/11 PHP Functions o Funtions don’t have a return type. o Can return anything. o The function name can start with a letter or underscore (not a number). function functionName () { code to be executed ; }
15
03/02/11 An Example <?php function go_wncc() { echo “Now, you have the power of php"; } go_wncc(); ?> Link : http://localhost/ex/ex3.phphttp://localhost/ex/ex3.php
16
03/02/11 PHP include include() or require() function. include() generates the warning but the script continues. require() generates error, and the script will stop. Helps to avoid redundancy in code.
17
03/02/11 PHP Sessions What if you want to store some temporary data on the server ? Sessions help you to store data temporarily on the server for an user. Will be deleted when user leaves the website.
18
03/02/11 Useful links and tutorials www.w3schools.com www.tizag.com www.google.com Explore yourself and have fun……. Thank you!!!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.