Download presentation
Presentation is loading. Please wait.
Published byIlene Stanley Modified over 8 years ago
1
UNIVERISTY OF SOMALIA College of Engineering and Computer Science Course code: N/A COURSE: WEB DEVELOPMENT WITH PHP --------------------------------------------- THE KEY TO THE PHP Class: CS12F 09-10- 2015 THIRD week Lecturer: Mohamed-Nur Hussein Abdullahi Hame (M.Sc in CSE) - - - - - - - - - - - - - - - - - - - - - - - - 10:30 -12: 30 Course time
2
SYNTAX, VARIABLES, COMMENTS, OPERATORS AND CONTROL STRUCTURES PROGRAMMING WITH PHP
3
OPENING AND CLOSING PHP (This is the most used to open and close PHP) or (ASP style, considered as bad form) or (ASP style, very bad form)
4
PHP’s Syntax Is C-Like If you know how to program with C language, it’s helpful PHP is whitespace insensitive. PHP is not a case sensitive language but sometimes PHP 0is case sensitive. Statements are expressions terminated by semicolons. A statement in PHP is any expression that is followed by a semicolon (;) Expressions are combinations of tokens.
5
Comments C-style multiline comments /* This is a comment in PHP */ Single-line comments: # and // # This is a comment, and # this is the second line of the comment // This is a comment too
6
PHP VARIABLES
7
PHP variables are Perl-like All variables in PHP are denoted with a leading dollar sign ($). The value of a variable is the value of its most recent assignment. Variables are assigned with the = operator. Variables can, but do not need, to be declared before assignment. Variables have no basic type other than the type of their current value. No variable type declaration, php converts data types automatically Variables used before they are assigned have default values No spaces in the variables, and they are case sensitive.
8
ASSIGNING, REASSIGNING VARIABLES $JusNumber = 3.33+11; REASSIGNING: $Var = “This is just a text”; $Var = 55; If the second statement immediately follows the first one, the first statement has essentially no effect.
9
PHP OPERATORS Arithmetic operators: + - * / % Logical operators: and, or, !, &&, || Comparison operators: ==, !=,, = Identity operator (===): True if its arguments are equal to each other and of the same type, but false otherwise.
10
Operators of Note Increment / Decrement ( ++ -- ) String concatenation (. ) Equality ( == != ) Identity ( === !== ) Ternary ( ? : ) Side-effect Assignment ( += -=.= etc.)
11
Increment / Decrement These operators allow you to both retrieve and increment / decrement a variable. $x = 12; $y = 15 + $x++; echo "x is $x and y is $y \n";
12
String Concatenation PHP uses the period character for concatenation because the plus character would instructor PHP to to the best it could do to add the two things together, converting if necessary. $a = 'Hello '. 'World!'; echo $a. "\n";
13
Ternary operator The ternary operator comes from C. It allows conditional expressions. It is like a one-line if-then-else. $www = 123; $msg = $www > 100 ? "Large" : "Small" ; echo "First: $msg \n"; $msg = ( $www % 2 == 0 ) ? "Even" : "Odd"; echo "Second: $msg \n"; $msg = ( $www % 2 ) ? "Odd" : "Even"; echo "Third: $msg \n";
14
EXAMPLES
15
EXAMPLE 1 – Assigning by reference OUTPUT: Let me tell you that I love Hiiraan
16
EXAMPLE 2 – Assign by value OUTPUT: Hiiraan
17
EXAMPLE 3 – Using print instead of echo <?php $many = 5; $many_2 = 7; $few = $many + $many_2; print("$many + $many_2 = $few "); ?> OUTPUT: 5 + 7 = 12
18
EXAMPLE 4 – Using single and double quotations <?php $variable = "name"; $literally = 'My $variable will not print!'; print($literally); print " "; $literally = "My $variable will print!"; print($literally); ?> OUTPUT: My $variable will not print! My name will print
19
EXAMPLE 5 – Displaying HTML code <?php // Displaying HTML code echo " This is a simple heading. "; echo " This is heading with style. " ?> OUTPUT: This is a simple heading. This is heading with style.
20
THANK YOU!
21
ANY QUESTIONS?
22
ABOUT THE LECTURER mohanur252@gmail.com Facebook.com/hame2011 @mohanur252 Mohamed-Nur Hussein Master of science in Computer Science & Engineering @ Daffodil International www.mohanur.com FEEL FREE TO CONTACT ME: Recommendation: The following fonts are required for better presentation resolution: (Aachen BT, Franklin Gothic Demi Cond, Rockwell, Calibri, Calibri Light (Headings), Arial) +252 61 5 713333 +252 62 5 713333 +252 69 5 713333 (Dhaka – Bangladesh) --------------------------------------------- ---- Freelancer and website designer Part-time lecturer at: University of Somalia (UNISO) --------------------------------------------- ---- ANY FEEDBACK OR SUGESSIONS? PLEASE LET ME KNOW IF YOU HAVE ANY FEEDBACK REGARDING THE COURSE. THANKS! ---------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.