0% found this document useful (0 votes)
54 views28 pages

PHP Beginner 2018 02

This document provides an overview and agenda for a presentation on PHP and MySQL. It discusses installing packages like WAMP, XAMPP or MAMP to run PHP, Apache, MySQL and PHPMyAdmin locally. It covers PHP basics like code blocks, data types, variables, operators, and functions. Key points include using short open and close tags for PHP code, different variable scopes, and escape sequences to handle quotes in strings. The document aims to introduce fundamental PHP concepts and help get started with a local development environment for PHP and MySQL.

Uploaded by

malas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views28 pages

PHP Beginner 2018 02

This document provides an overview and agenda for a presentation on PHP and MySQL. It discusses installing packages like WAMP, XAMPP or MAMP to run PHP, Apache, MySQL and PHPMyAdmin locally. It covers PHP basics like code blocks, data types, variables, operators, and functions. Key points include using short open and close tags for PHP code, different variable scopes, and escape sequences to handle quotes in strings. The document aims to introduce fundamental PHP concepts and help get started with a local development environment for PHP and MySQL.

Uploaded by

malas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

PHP: Hypertext Preprocessor

PHP & MySQL 02


Jibril Abdiqadir Ahmed
IT Engineer & lecturer
Feb. 2018
Agenda

 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

 On windows WAMP, XAMPP or MAMP can be installed


 On MAC XAMPP or MAMP can be installed
 On Linux LAMP can be installed
 All of them runs
 Apache – a Web Server
 PHP - Server Side Language
 MySQL / MariaDB – DBMS - DataBase Management System
 PHPMyAdmin
 (PERL)
PHP Configuration
 PHP .ini
Php configuration file is read when php starts up. Values of different environment
variables can be set in php.ini file. Outputs a lot of data about the PHP installation
 Some of the features are:
 Version information
 Installed extension
 Server environment variables
 Execution time
 File upload size and so on
 Session paths
 Upload file size
 Short tags
 Error reporting
 Safe mode
PHP Quick start.
PHP - ”Hello World!”
PHP Documentation
 Available at http://php.net/manual
 Shortcut specific word. http://php.net/abc eg.
 http://php.net/phpinfo
 http://php.net/install
 http://php.net/install.windows
 Also available for download and offline browsing (download all php manual)
PHP Basics: Code Blocks
Code Blocks:
 Standard Tags: <?php ...... ?>
 Short Tags: <?........ ?>
 ASP Tags: <%.....%> (Removed from php 7.0)
 Script Tags
 <script language=“PHP”></script> (Removed from PHP 7.0)
PHP Basics
Language Constructs:
 Constructs are elements that are built-into the language.
 Echo
 Echo 10;
 Every statement ends with semi colon.

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

 Add variable to variable or combine variable with dot


PHP String uppercase / lowercase function

 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;

 // Outputs 1, $a is now equal to 2


 echo $a++;

 // Outputs 3, $a is now equal to 3


 echo ++$a;

 // Outputs 2, $a is now equal to 2


 echo --$a;

 // Outputs 2, $a is now equal to 1


 echo $a--;
Operators: Arithmetic Operators
 Addition
 $a = 1 + 3.5;
 Subtraction
 $a = 4 - 2;
 Multiplication
 $a = 8 * 3;
 Division
 $a = 15 / 5;
 Modulus
 $a = 23 % 7;
Concatenation - Assignment Operator
 $string = “PHP" . “MySql";
 $string2 = “Zend";
 $string .= $string2;
 echo $string;
 Will print: PHP MySql Zend

PHP Basics: Operator Precedence
 $x = 9 + 1 * 10
 Expecting result 100 but getting 19 – Multiplication has higher precedence

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

You might also like