PHP Beginner 2018 02
PHP Beginner 2018 02
Install XAMP
Hello World
DataTypes
Construct
Installing PHP
http://php.net/downloads.php
(Source code & Binaries)
http://windows.php.net/
(Windows binaries)
https://www.apachefriends.org
(All-in-One)
WAMP / XAMPP / MAMP/ LAMP Installation
Comments
Single line comments –
// this is a single line comment
# this is a single line comment
Multi Line Comments - /* ….. */
/* This is a Multi line comment
*/
PHP Basics: Data Types
Data Types:
Scalar Data types
Integer (Signed)
String
Float (floating point numbers - also called double)
Boolean
Composite
Arrays
Objects
NULL
Resource
PHP Basics: Data Types
Data Types:
Integer examples:
echo 10;
echo -123;
echo 066;
echo 0xFF;
Floating Point
echo 10.2;
echo 0.009;
echo 2E7;
echo 1e2;
PHP Basics: Data Types
Data Types:
String examples:
echo “ String in double quotes”;
echo ‘ string in single quotes’;
Boolean
True or False;
Composite Data types
Arrays
Objects
Null
Resource
PHP Basics: Variables
PHP is a loosely typed language
Variables are storage container in memory
Variables are identified with $ sign:
$firstname = “Jibril”;
$lastname = “Ahmed”;
Valid variables:
[a-zA-Z], numbers, underscores
Variable variable
contents of variable to reference a new variable
PHP Basics: Variables
PHP String
Difference between single qoutes
and double quotes :
String examples:
echo “ String in double quotes”;
echo ‘ string in single quotes’;
Combination
Echo with single qoutes
Echo with double qoutes
Use curly brackets / braces to split
from other text.
{$color} examlpe:
PHP Variables - Global and Local Scope
In PHP, variables can be declared anywhere in the script.
The scope of a variable is the part of the script where the variable can be
referenced/used.
PHP has three different variable scopes:
local
global
Static
A variable declared outside a function has a GLOBAL SCOPE and can only be accessed
outside a function.
A variable declared within a function has a LOCAL SCOPE and can only be accessed
within that function.
The global keyword is used to access a global variable from within a function.
To do this, use the global keyword before the variables (inside the function)
PHP String combine with dot
Returns:
PHP String functions
PHP Basics: Variables
Variables existence
Isset (boolean)
<?php
$var = '';
// This will evaluate to TRUE so the text will be printed.
if (isset($var)) {
echo "This var is set so I will print.";
} ?>
Destroying
unset
Constants (are not allowed to be redefined)
define(“country", “United States");
echo country;
define("MAXSIZE", 100);
echo MAXSIZE;
PHP Basics: Operators
Operators are the catalysts of operations:
Assignment Operators =
Arithmetic Operators + - / * %
String Operators .
Comparison Operators < > <= >= Ternary operator
Logical Operators && || ! XOR
Bitwise Operators | & XOR NOT
Error Control Operators
Incrementing / Decrementing Operators ++ --
Typeof
Operators: Increment / Decrement
// Assign the integer 1 to $a
$a = 1;
Highest Precedence
*/%
+-.
< <= > >= &&
||
And
Xor or
Lowest precedence
PHP Basics: Escape Sequences
\" Print the next character as a double quote, not a string closer
\' Print the next character as a single quote, not a string closer
\n Print a new line character (remember our print statements?)
\t Print a tab character
\r Print a carriage return (not used very often)
\$ Print the next character as a dollar, not as part of a variable
\\ Print the next character as a backslash, not an escape character
$MyString = "This is an \"escaped\" string";
$MySingleString = 'This \'will\' work';
$MyNonVariable = "I have \$marks in my pocket";
$MyNewline = "This ends with a line return\n";
$MyFile = "c:\\windows\\system32\\myfile.txt";
Thanks