PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming...
-
Upload
jerome-martin -
Category
Documents
-
view
217 -
download
1
Transcript of PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming...
![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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/1.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/2.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/3.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/4.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/5.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/6.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/7.jpg)
Į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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/8.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/9.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/10.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/11.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/12.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/13.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/14.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/15.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/16.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/17.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/18.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/19.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/20.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022062422/56649f135503460f94c27368/html5/thumbnails/21.jpg)
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