21
PHP Arūnas Liuiza

PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

Embed Size (px)

Citation preview

Page 1: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

PHPArūnas Liuiza

Page 2: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

PHP 101

Page 3: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

What is PHP?

Widely popular dynamic interpreted opensource programming language, aimed for web development

Syntax is simmilar to C, Perl, Java

PHP code snippets can be inserted to a HTML document

Page 4: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

PHP Syntax

Page 5: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

Inserting to HTML

Long tags <?php ... ?> <script language=“php”> ... </script>

Short tags <? ... ?> ir <?= ... ?> <% ... %> ir <%= ... ?>

Not recommended due to compatability reasons

Page 6: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

Output

Main function to output data: echo

echo “Hello”; echo 12345;

Page 7: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

ĮTERPIMAS Į HTML. PAVYZDYS

Page 8: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

Instruction separation

Semicolon (;) is used to separate instructions from one another

<?php echo “foo”; echo “bar”;?>

Page 9: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

Comments

PHP has three types of comments

Single line (till the end of line or ?>) : // comment # comment

Multi-line /* comment

carries to another line and another… */

Page 10: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

Variables Symbolic name, that

can have a value assigned to it

Starts with dollar ($) sign $first

First symbol has to be a letter or an underscore (_) $start $_with_underscore

Can also contain numbers $p123_44dlsdm_ $_1234ps

Variable names are Case Sensitive $Pirmas != $pirmas $DuKartai != $dukartai

Page 11: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

Variables. Examples

$foo = 15;echo ‘foo is ‘.$foo;

$foo = “Peter”;echo ‘foo is ‘.$foo;

$foo = “Peter”;$foo = “John”;echo ‘foo is ‘.$foo;

foo is 15

foo is Peter

foo is John

Code Result

Page 12: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

Main PHP data types

Boolean Logical true/false

Integer 1, 2, 3, 4…

Float 3.1415, 0.21513

String ‘Text’

Array

Object

Resource

NULL No value

Page 13: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

BOOLEAN Logical true or false value

$a = true; $a = FaLsE;

Possible FALSE values: FALSE 0 0.0 ‘’ ir ‘0’ Empty array Object without members NULL

Anything else - TRUE

Page 14: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

Type casting

PHP does not require strict definition of variable data type – type is converted according to context

Page 15: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

Operators

PHP operators are divided to: Arithmetical Value assigning Comparison Logical

Page 16: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

Arithmetical

+ Sum $a = 2 + 2

- Subtract $a = 4 – 2

* Multiply $a = 2 * 2

/ Divide $a = 4 / 2

% Division module $a = 5 % 2 (=1)

++

Add 1 ++$a

-- Subtract 1 --$a

. Connect two strings

$a = “raga” . “nosis”

Page 17: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

Value assigning

= $x = $y

+=

$x += $y $x = $x + $y

-= $x -= $y $x = $x - $y

*= $x *= $y $x = $x * $y

/= $x /= $y $x = $x / $y

.= $x .= $y $x = $x . $y

%=

$x %= $y $x = $x % $y

Page 18: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

Comparison

==

Equal 5==8 false

!= Not equal 5!=8 true

<>

Not equal 5<>8 true

> More 5>8 false

< Less 5<8 true

>=

More or equal 5>=8 false

<=

Less or equal 5<=5 true

Page 19: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

Logical

&& AND

|| OR

! NOT

Page 20: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

Exercise

Page 21: PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar

Task no 1

1. Multiply N by 32. Add 15 to the result3. Find module of

division by 4 of the result

4. Add 2 to the result5. Raise the result to

the second power (Res2)

6. Subtract 1.5 from the result

7. Divide result by 3

Write a program that executes the operations one by one, outputing the result after each operation