Presentation is loading. Please wait.

Presentation is loading. Please wait.

FP512 WEB PROGRAMMING 1 PREPARED BY: PN. NUR SYUHADA BINTI MOHAMAD.

Similar presentations


Presentation on theme: "FP512 WEB PROGRAMMING 1 PREPARED BY: PN. NUR SYUHADA BINTI MOHAMAD."— Presentation transcript:

1 FP512 WEB PROGRAMMING 1 PREPARED BY: PN. NUR SYUHADA BINTI MOHAMAD

2 1. Apply the basic structure of PHP syntax and program. 2. Create classes and objects in PHP environment. 3. Use functions in PHP environment. 4. Use arrays and strings in PHP environment. 5. Create PHP web form. 6. Process web form data. 7. Understand cookies and sessions. Learning Outcomes

3 3.1 Apply the basic structure of PHP syntax and program.

4 PHP Syntax PHP script always starts with Shorthand-support, The others tags that also can be use:,, Example, index.php:

5 PHP must end with a semicolon ( ; ) Two basic statements to output text with PHP: – echo a language construct that has no return value and cannot be used in an expression. – print behaves like a function with its own return value (although it is a language construct), can be used in an expression. Statement in PHP

6 // to make a single-line comment /* and */ to make a large comment block or multi line comment. Comment in PHP

7 PHP variables are used to hold values or expressions. Rules for PHP variable names: – Variables in PHP starts with a $ sign, followed by the name of the variable – The variable name must begin with a letter or the underscore character – A variable name can only contain alphanumeric characters and underscores (A-z, 0-9, and _ ) PHP Variables

8 – A variable name should not contain spaces. – Variable names are case sensitive (y and Y are two different variables) Create a variable containing a string, and a variable containing a number:

9 A variable declared within a PHP function is local and can only be accessed within that function Local Scope Variables

10 Any variable that is defined outside of any function Accessed from any part of the script that is not inside a function Global Scope Variables Output: 15 $GLOBALS['b'] = $GLOBALS['a'] + $GLOBALS['b'];

11 Operator An operator is a symbol or series of symbols that, when used in conjunction with values, perform an action and usually produces a new value. An operand is a value used in conjunction with an operator. There are usually two or more operands to one operator.

12 Arithmetic operators OperatorNameExampleSample Result +Addition10 + 313 -Subtraction10 – 37 /Division10 / 33.33333333333 *Multiplication10 * 330 %Modulus10 % 31

13 The assignment operator (=) Basic assignment operator in PHP is "=". Example: The value of "$x = 5" is 5.

14 Incrementing/Decrementing Operators

15 Comparison between two values Comparison Operators

16 Logical Operators

17 Concatenation operator Concatenation operator (.) is used to put two string values together. For example: Output: Hai Amy! Have a nice day !

18 Constants in PHP A constant is an identifier (name) for a simple value. It’s function returns the value of constant. Syntax: constant(constant ) Output: I love PHP

19

20 <?php echo "Twinkle, Twinkle little star. "; $twinkle="Twinkle"; $star="star"; echo "$twinkle, $twinkle little $star. "; $twinkle="Thunder"; $star="elephant"; echo "$twinkle, $twinkle little $star."; ?> Q1: Uses of Variable

21 Q1: Answer

22 <?php $num = 8; echo "Value is now $num. "; $num += 2; echo "Add 2. Value is now $num. "; $num -= 4; echo "Subtract 4. Value is now $num. "; $num *= 5; echo "Multiply by 5. Value is now $num. "; $num /= 3; echo "Divide by 3. Value is now $num. "; $num++; echo "Increment value by one. Value is now $num. "; $num--; echo "Decrement value by one. Value is now $num."; ?> Q2: Arithmetic Operators

23 Q2: Answer Value is now 8. Add 2. Value is now 10. Subtract 4. Value is now 6. Multiply by 5. Value is now 30. Divide by 3. Value is now 10. Increment value by one. Value is now 11. Decrement value by one. Value is now 10.

24 Q3: Arithmetic & Assignment Operators <?php $x=10; $y=7; $result=$x+$y; echo "$x + $y = $result "; $result=$x-$y; echo "$x - $y = $result "; $result=$x*$y; echo "$x * $y = $result "; $result=$x/$y; echo "$x / $y = $result "; $result=$x%$y; echo "$x % $y = $result "; ?>

25 10 + 7 = 17 10 - 7 = 3 10 * 7 = 70 10 / 7 = 1.4285714285714 10 % 7 = 3 Q3: Answer

26


Download ppt "FP512 WEB PROGRAMMING 1 PREPARED BY: PN. NUR SYUHADA BINTI MOHAMAD."

Similar presentations


Ads by Google