Top Banner
32

PHP in one presentation

Jul 19, 2015

Download

Software

Milad Rahimi
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: PHP in one presentation
Page 2: PHP in one presentation

Desktop Application

Runs on a single-PC

Page 3: PHP in one presentation

Enterprise Application

Runs on a network

Page 4: PHP in one presentation

Web Application

Runs on the Internet

Page 5: PHP in one presentation

Request >< Response

Web Application

Client Network Server

Your app

goes here

Page 6: PHP in one presentation

HTML is a markup language for

describing web pages.

HTML

Page 7: PHP in one presentation
Page 8: PHP in one presentation

is created by Rasmus Lerdorf in 1994.

stands for “Personal Home Page”.

is influenced by C, C++, Java and TCL.

competes with JSP, ASP.NET, Perl and etc.

is used to create FB, Wikipedia, WP and etc.

is used in 60-70% of the world’s websites.

PHP is free software under the PHP License.

Intro

Page 9: PHP in one presentation

Server:

Environment

On your own PC:

Page 10: PHP in one presentation

IDEs

Page 11: PHP in one presentation

Syntax

Functional and Object Oriented

Page 12: PHP in one presentation

Integers are platform-dependent equivalent to the C long type.

Data Types

Floating point numbers are also stored in a platform-specific range.

Boolean type is similar to the native Boolean types in Java and C++.

Resource type represent references to external sources.

Arrays can contain elements of any type that PHP can handle

Integer . Double . Booleans . NULL . String . Array . Object . Resource

Data Types:

Page 13: PHP in one presentation

Variable

Variables: <?php $number = 666; ?>

Constants: <?php define(“Name”, “Value”); ?>

Strings: <?php

$string = “Text”;

$string2 = $string . “Extra”;

?>

In Strings: <?php echo “Variable = $variable”; ?>

Casting: <?php $number = (int) $string; ?>

Page 14: PHP in one presentation

+

-

*

/

%

++

--

Operators

Arithmetic . Comparison . Logical . Assignment==

!=

>

<

>=

<=

And

Or

&&

||

!

=

+=

-=

*=

/=

%=

Page 15: PHP in one presentation

$array[0], $array[1], $array[3], …

Array

Numeric:

$person[“name”], $person[“surname”], $person[“age”]

Associative:

$outside[key] = $inside;

Multidimensional:

Page 16: PHP in one presentation

Array

Page 17: PHP in one presentation

Decision Making

If … Else if … else … Switch

x = a ? b : c;

Page 18: PHP in one presentation

Loop

Page 19: PHP in one presentation

Functionfunction write($message) {

echo $message;

}

function add($num1, $num2) {

return $num1 + $num2;

}

Normal functions are not first-class.

User-defined functions can be created at any time without prototype.

Functions can be defined inside code blocks, permitting a

run-time decision as to whether or not a function should be defined.

Support for true anonymous functions is not exist in PHP.

Page 20: PHP in one presentation

Closurefunction getAdder($x)

{

return function($y) use ($x)

{

return $x + $y;

};

}

$adder = getAdder(8);

echo $adder(2); // prints "10"

Page 21: PHP in one presentation

OOP

class Student {

Private $name;

Private $surname;

Private $No;

public function getName() {

return $this->name;

}

}

Define Class:

$student = new Student();

echo $student->getName();

Create Object:

Page 22: PHP in one presentation

OOP

class Student {

Private $name;

Private $surname;

Private $No;

public function __construct() {

// codes…

}

}

Constructor:

class Student {

Private $name;

Private $surname;

Private $No;

public function __destruct() {

// codes…

}

}

Destructor:

Page 23: PHP in one presentation

OOP

class Child extends Parent {

<body>

}

Inheritance

Public *

Private

Protected

Encapsulation:

Page 24: PHP in one presentation

OOP

interface Mail {

public function sendMail();

}

class Report implements Mail {

public function sendMail() {

// implementation…

}

}

Interface:

abstract class Sample {

abstract function method1() ;

function method2() {

// implementation…

}

}

$sample = new Sample(); // Err

Abstract Class:

Page 25: PHP in one presentation

OOP

class Sample {

public static $xxx;

static function abc() {

// implementation…

}

}

echo Sample::xxx;

echo Sample::abc();

Statics:

class Sample {

final public function abc() {

// final implementation

}

}

Note:

Properties cannot be declared final

Final:

Page 26: PHP in one presentation

Exception

try {

// Codes to run

} catch(Exception $e) {

// Process exception

} finally { // PHP 5.4

// Do anyway!

}

Syntax:throw new Exception($message);

Throw

echo $e->getMessage();

Catch

Page 27: PHP in one presentation

Exception

$x = $_GET[“number”];

try {

if($x>1000)

throw new Exception(“Too big!”);

echo “The number is: “ . $x;

} catch (Exception $e) {

echo “Error: “ . $e->getMessage();

}

Example:

Page 28: PHP in one presentation

HTML Form

Page 29: PHP in one presentation

Cookie

setcookie(name, value, expire, path, domain, security);

Create:

$_COOKIE["name"];

Access:

setcookie(“Name", “Hasan Teymuri", time()+3600, "/","", 0);

Example:

Page 30: PHP in one presentation

Session

session_start();

Get Started:

$_SESSION [“Name"] = “Vahid Dehghani”;

Create:

echo $_SESSION[“Name”];

Access:

Page 31: PHP in one presentation

Hosting

Linux (CentOS)

Platform:

VPS (VDS)

Plan:

Direct Admin

Ctrl Panel:

Page 32: PHP in one presentation

The End

Main Source: http://tutorialspoint.com

Special thanks to Google, Wikipedia

and who has invented copy-and-paste!

Written By

Milad Rahimi [www.MiladRahimi.com]