SlideShare a Scribd company logo
Introduction to PHP Jussi Pohjolainen TAMK University of Applied Sciences
WEB PROGRAMMING CONCEPTS
Three-tiered Web Site: LAMP Client User-agent: Firefox Server Apache HTTP Server example request GET / HTTP/1.1 Host:  www.tamk.fi User-Agent: Mozilla/5.0 (Mac..) ... response Database MySQL PHP
Java EE Architecture (x)html / xml Applet Client Application J2EE Application Server Web Container Servlets JSP JSPs Servlets EJB Container RMI/IIOP JNDI JTA JDBC JMS JavaMail JAF Session   Beans Entity Beans Msg-Driven Beans RMI/IIOP JNDI JTA JDBC JMS JavaMai l JAF HTTP(S) JDBC JavaMail RMI IIOP JNDI JMS DB Java-Application CORBA Server Message Queue Directory Service Client Mail Server
Server Side Techniques Server side scripting requires installation on the server side Typically client siis only xhtml and it unaware that the xhtml was produced by a server side script Does not require any installations or add-ons  on the client
Server Side Techniques PHP Java EE: Servlet, JSP .NET CGI / Perl (Very old) Ruby …
Client Side Techniques Requires that the client supports the technique JavaScript, Applet, Flash…
Web Application Frameworks A web application framework is a software framework that is designed to support the development of dynamic websites, Web applications and Web services. Numerous frameworks available for many languages
Web App vs. Web Site? What’s the difference between Web App and Web Site? Rich Internet Application?, AJAX?, Thin Client? Full application running in your browser or just a web site?
PHP: HYPERTEXT PREPROCESSOR
Introduction to PHP PHP is a computer scripting language. Originally designed for producing dynamic web pages Appeared in 1995 PHP Group is responsible for the language, no formal specification Free software Runs on most operating systems and platforms URL: http://www.php.net
Response
Introduction to PHP Syntax PHP has quite easy syntax, if you are familiar with any c-type language It has all the same structures that you are familiar with other programming languages PHP is designed to output to browser, but it is possible to do also CLI apps.
Example <?php print &quot;What is your name?\n&quot;; $name = trim(fgets(STDIN)); print &quot;Hello &quot; . $name; ?>
Variables Variables in PHP are represented by a dollar sign PHP supports eight types: boolean, integer, float, double, array, object, resource and NULL
Example (php.net) <?php $a_bool = TRUE;  // a boolean $a_str  = &quot;foo&quot;;  // a string $a_str2 = 'foo';  // a string $an_int = 12;  // an integer echo gettype($a_bool); // prints out:  boolean echo gettype($a_str);  // prints out:  string // If this is an integer, increment it by four if (is_int($an_int)) { $an_int += 4; } // If $bool is a string, print it out // (does not print out anything) if (is_string($a_bool)) { echo &quot;String: $a_bool&quot;; } ?>
Naming Variables Case-sensitivity Start with letter or _ After that you can have numbers, letters and _ $var = 'Bob'; $Var = 'Joe'; print &quot;$var, $Var&quot;;      $4site = 'not yet';     $_4site = 'not yet';   
Constants You cannot alter the value of constant after declaration define(CONSTANT, &quot;value&quot;); print CONSTANT;
Magic Constants PHP has lot of predefined variables Also predefined constants: __LINE__ __FILE__ __FUNCTION__ __CLASS__ __METHOD__ See: http://fi.php.net/manual/en/language.constants.predefined.php
Scope <?php $a = &quot;Pekka&quot;; print ”My name is &quot; . $a; ?>
Scope <?php $a = &quot;Pekka&quot;; function Test() { print $a; } print ”My name is ”; Test(); ?>
Scope <?php $a = &quot;Pekka&quot;; function Test() { global $a; print $a; } print ”My name is ”; Test(); ?>
Control Structures If, else, elseif, switch while, do-while, for foreach break, continue
PHP BASICS
Strings Single quoted:  'this is a $variable' Double quoted:  &quot;this is a $variable&quot; Heredoc: $str = <<<EOD Example of string spanning multiple lines using heredoc syntax. EOD;
Modifying the String $mj = &quot;moi&quot;; print $mj[0]; $mj[0] = 'x'; print $mj; $mj = $mj . &quot; hei&quot;; print $mj; $mj .= &quot; terse&quot;; print $mj;
String functions A lot of functions… http://www.php.net/manual/en/ref.strings.php
Statements Every statement ends with ; $a = 5; $a = function(); $a = ($b = 5); $a++;  ++$a; $a += 3;
Operators Arithmethic: +,-,*,% Setting variable: = Bit: &, |, ^, ~, <<, >> Comparison: ==, ===, !=, !==, <, > <=, >=
Ternary Operator $variable = (1 < $x) ? 'value1' : 'value2'; Equals if(1 < $x) { $variable = 'value1'; } else { $variable = 'value1'; }
Execution Operator Execute command in shell $result = `ls -al`; print $result; Does the same than  shell_exec()  - function
Logical Operators $a and $b $a or $b $a xor $b !$a; $a && $b; $a || $b;
String Operators Two operators for strings: '.' and '.=' '.' – combining strings. '.=' – appends string to the end. Example: $v= &quot;Hello&quot; . $b; $v.= &quot;Hello&quot;;
Arrays See  http://php.tpu.fi/~pohjus/lectures/php/php-arrays.html
CONTROL STRUCTURES
IF <?php if ($a > $b) {     echo &quot;a is bigger than b&quot;; } else {     echo &quot;a is NOT bigger than b&quot;; } if ($a > $b) {     echo &quot;a is bigger than b&quot;; } elseif ($a == $b) {     echo &quot;a is equal to b&quot;; } else {     echo &quot;a is smaller than b&quot;; } ?>
While and Do-While <?php $a=0; while($a<10){ print $a; $a++; } $i = 0; do {     print $i; } while ($i > 0); ?>
For for ($i = 1; $i <= 10; $i++) {     print $i; }
Foreach $arr = array(1, 2, 3, 4); foreach ($arr as $value) {     echo $value; }
Switch switch ($i) { case 0:     echo &quot;i equals 0&quot;;     break; case 1:     echo &quot;i equals 1&quot;;     break; case 2:     echo &quot;i equals 2&quot;;     break; }
PHP COMBINED WITH XHTML
Response
Example: spaghetti-way <!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;> <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;> <head> <title>xhtml-doku</title> <meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /> </head> <body> <h1>Title</h1> <?php    print &quot;<p>Hello from PHP!</p>&quot;; ?> </body> </html>
Better ways Use functions Use OO
PHP AND USER INPUT
PHP and User Input via Forms See http://php.tpu.fi/~pohjus/lectures/php/forms-and-php.html

More Related Content

What's hot (20)

JavaScript Basic
JavaScript BasicJavaScript Basic
JavaScript Basic
Finsa Nurpandi
 
Servlets
ServletsServlets
Servlets
ZainabNoorGul
 
Jquery
JqueryJquery
Jquery
Girish Srivastava
 
1 03 - CSS Introduction
1 03 - CSS Introduction1 03 - CSS Introduction
1 03 - CSS Introduction
apnwebdev
 
PHP
PHPPHP
PHP
Steve Fort
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
Santhiya Grace
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
Walid Ashraf
 
Form Handling using PHP
Form Handling using PHPForm Handling using PHP
Form Handling using PHP
Nisa Soomro
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
WordPress Memphis
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
WebStackAcademy
 
jQuery
jQueryjQuery
jQuery
Dileep Mishra
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
Bootstrap 5 basic
Bootstrap 5 basicBootstrap 5 basic
Bootstrap 5 basic
Jubair Ahmed Junjun
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
Shweta A
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
Compare Infobase Limited
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
Bala Narayanan
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
Purbarun Chakrabarti
 
Node.js Express Framework
Node.js Express FrameworkNode.js Express Framework
Node.js Express Framework
TheCreativedev Blog
 
Javascript
JavascriptJavascript
Javascript
mussawir20
 

Viewers also liked (6)

Introduction to Mysql
Introduction to MysqlIntroduction to Mysql
Introduction to Mysql
Tushar Chauhan
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
webhostingguy
 
Introduction to MySQL
Introduction to MySQLIntroduction to MySQL
Introduction to MySQL
Giuseppe Maxia
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Vikash Singh
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
Manish Bothra
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTML
MayaLisa
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Vikash Singh
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTML
MayaLisa
 
Ad

Similar to Introduction to PHP (20)

What Is Php
What Is PhpWhat Is Php
What Is Php
AVC
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
webhostingguy
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
Karmatechnologies Pvt. Ltd.
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
isadorta
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
kalaisai
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
Digital Insights - Digital Marketing Agency
 
Web development
Web developmentWeb development
Web development
Seerat Bakhtawar
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Kengatharaiyer Sarveswaran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Muhamad Al Imran
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
Muhamad Al Imran
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Muhamad Al Imran
 
PHP MySQL
PHP MySQLPHP MySQL
PHP MySQL
Md. Sirajus Salayhin
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009
cwarren
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0
Cathie101
 
Php
PhpPhp
Php
Ajaigururaj R
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
What Is Php
What Is PhpWhat Is Php
What Is Php
AVC
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
webhostingguy
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
isadorta
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
kalaisai
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Muhamad Al Imran
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Muhamad Al Imran
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009
cwarren
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0
Cathie101
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
Ad

More from Jussi Pohjolainen (20)

Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
Jussi Pohjolainen
 
Java Web Services
Java Web ServicesJava Web Services
Java Web Services
Jussi Pohjolainen
 
Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
Jussi Pohjolainen
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
Jussi Pohjolainen
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
Jussi Pohjolainen
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
Jussi Pohjolainen
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
Jussi Pohjolainen
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
Jussi Pohjolainen
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Jussi Pohjolainen
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
Jussi Pohjolainen
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
Jussi Pohjolainen
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
Jussi Pohjolainen
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
Jussi Pohjolainen
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
Jussi Pohjolainen
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Jussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
Jussi Pohjolainen
 
Intro to Asha UI
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
Jussi Pohjolainen
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
Jussi Pohjolainen
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
Jussi Pohjolainen
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
Jussi Pohjolainen
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
Jussi Pohjolainen
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
Jussi Pohjolainen
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Jussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
Jussi Pohjolainen
 

Recently uploaded (20)

How to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 WebsiteHow to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 Website
Celine George
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
RVSPSOA
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptxRai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Dashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo SlidesDashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo Slides
Celine George
 
Pharmaceutical_Incompatibilities.pptx
Pharmaceutical_Incompatibilities.pptxPharmaceutical_Incompatibilities.pptx
Pharmaceutical_Incompatibilities.pptx
Shantanu Ranjan
 
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in IndiaSmart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
fincrifcontent
 
Uterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managmentUterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managment
Ritu480198
 
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
Sritoma Majumder
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
WRITTEN THEME ROUND- OPEN GENERAL QUIZ.pptx
WRITTEN THEME ROUND- OPEN GENERAL QUIZ.pptxWRITTEN THEME ROUND- OPEN GENERAL QUIZ.pptx
WRITTEN THEME ROUND- OPEN GENERAL QUIZ.pptx
Sourav Kr Podder
 
Freckle Project April 2025 Survey and report May 2025.pptx
Freckle Project April 2025 Survey and report May 2025.pptxFreckle Project April 2025 Survey and report May 2025.pptx
Freckle Project April 2025 Survey and report May 2025.pptx
EveryLibrary
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
LDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-inLDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-in
LDM & Mia eStudios
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
How to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 WebsiteHow to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 Website
Celine George
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
RVSPSOA
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
Dashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo SlidesDashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo Slides
Celine George
 
Pharmaceutical_Incompatibilities.pptx
Pharmaceutical_Incompatibilities.pptxPharmaceutical_Incompatibilities.pptx
Pharmaceutical_Incompatibilities.pptx
Shantanu Ranjan
 
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in IndiaSmart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
fincrifcontent
 
Uterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managmentUterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managment
Ritu480198
 
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
Sritoma Majumder
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
WRITTEN THEME ROUND- OPEN GENERAL QUIZ.pptx
WRITTEN THEME ROUND- OPEN GENERAL QUIZ.pptxWRITTEN THEME ROUND- OPEN GENERAL QUIZ.pptx
WRITTEN THEME ROUND- OPEN GENERAL QUIZ.pptx
Sourav Kr Podder
 
Freckle Project April 2025 Survey and report May 2025.pptx
Freckle Project April 2025 Survey and report May 2025.pptxFreckle Project April 2025 Survey and report May 2025.pptx
Freckle Project April 2025 Survey and report May 2025.pptx
EveryLibrary
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
LDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-inLDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-in
LDM & Mia eStudios
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 

Introduction to PHP

  • 1. Introduction to PHP Jussi Pohjolainen TAMK University of Applied Sciences
  • 3. Three-tiered Web Site: LAMP Client User-agent: Firefox Server Apache HTTP Server example request GET / HTTP/1.1 Host: www.tamk.fi User-Agent: Mozilla/5.0 (Mac..) ... response Database MySQL PHP
  • 4. Java EE Architecture (x)html / xml Applet Client Application J2EE Application Server Web Container Servlets JSP JSPs Servlets EJB Container RMI/IIOP JNDI JTA JDBC JMS JavaMail JAF Session Beans Entity Beans Msg-Driven Beans RMI/IIOP JNDI JTA JDBC JMS JavaMai l JAF HTTP(S) JDBC JavaMail RMI IIOP JNDI JMS DB Java-Application CORBA Server Message Queue Directory Service Client Mail Server
  • 5. Server Side Techniques Server side scripting requires installation on the server side Typically client siis only xhtml and it unaware that the xhtml was produced by a server side script Does not require any installations or add-ons on the client
  • 6. Server Side Techniques PHP Java EE: Servlet, JSP .NET CGI / Perl (Very old) Ruby …
  • 7. Client Side Techniques Requires that the client supports the technique JavaScript, Applet, Flash…
  • 8. Web Application Frameworks A web application framework is a software framework that is designed to support the development of dynamic websites, Web applications and Web services. Numerous frameworks available for many languages
  • 9. Web App vs. Web Site? What’s the difference between Web App and Web Site? Rich Internet Application?, AJAX?, Thin Client? Full application running in your browser or just a web site?
  • 11. Introduction to PHP PHP is a computer scripting language. Originally designed for producing dynamic web pages Appeared in 1995 PHP Group is responsible for the language, no formal specification Free software Runs on most operating systems and platforms URL: http://www.php.net
  • 13. Introduction to PHP Syntax PHP has quite easy syntax, if you are familiar with any c-type language It has all the same structures that you are familiar with other programming languages PHP is designed to output to browser, but it is possible to do also CLI apps.
  • 14. Example <?php print &quot;What is your name?\n&quot;; $name = trim(fgets(STDIN)); print &quot;Hello &quot; . $name; ?>
  • 15. Variables Variables in PHP are represented by a dollar sign PHP supports eight types: boolean, integer, float, double, array, object, resource and NULL
  • 16. Example (php.net) <?php $a_bool = TRUE; // a boolean $a_str = &quot;foo&quot;; // a string $a_str2 = 'foo'; // a string $an_int = 12; // an integer echo gettype($a_bool); // prints out: boolean echo gettype($a_str); // prints out: string // If this is an integer, increment it by four if (is_int($an_int)) { $an_int += 4; } // If $bool is a string, print it out // (does not print out anything) if (is_string($a_bool)) { echo &quot;String: $a_bool&quot;; } ?>
  • 17. Naming Variables Case-sensitivity Start with letter or _ After that you can have numbers, letters and _ $var = 'Bob'; $Var = 'Joe'; print &quot;$var, $Var&quot;;      $4site = 'not yet';    $_4site = 'not yet';   
  • 18. Constants You cannot alter the value of constant after declaration define(CONSTANT, &quot;value&quot;); print CONSTANT;
  • 19. Magic Constants PHP has lot of predefined variables Also predefined constants: __LINE__ __FILE__ __FUNCTION__ __CLASS__ __METHOD__ See: http://fi.php.net/manual/en/language.constants.predefined.php
  • 20. Scope <?php $a = &quot;Pekka&quot;; print ”My name is &quot; . $a; ?>
  • 21. Scope <?php $a = &quot;Pekka&quot;; function Test() { print $a; } print ”My name is ”; Test(); ?>
  • 22. Scope <?php $a = &quot;Pekka&quot;; function Test() { global $a; print $a; } print ”My name is ”; Test(); ?>
  • 23. Control Structures If, else, elseif, switch while, do-while, for foreach break, continue
  • 25. Strings Single quoted: 'this is a $variable' Double quoted: &quot;this is a $variable&quot; Heredoc: $str = <<<EOD Example of string spanning multiple lines using heredoc syntax. EOD;
  • 26. Modifying the String $mj = &quot;moi&quot;; print $mj[0]; $mj[0] = 'x'; print $mj; $mj = $mj . &quot; hei&quot;; print $mj; $mj .= &quot; terse&quot;; print $mj;
  • 27. String functions A lot of functions… http://www.php.net/manual/en/ref.strings.php
  • 28. Statements Every statement ends with ; $a = 5; $a = function(); $a = ($b = 5); $a++; ++$a; $a += 3;
  • 29. Operators Arithmethic: +,-,*,% Setting variable: = Bit: &, |, ^, ~, <<, >> Comparison: ==, ===, !=, !==, <, > <=, >=
  • 30. Ternary Operator $variable = (1 < $x) ? 'value1' : 'value2'; Equals if(1 < $x) { $variable = 'value1'; } else { $variable = 'value1'; }
  • 31. Execution Operator Execute command in shell $result = `ls -al`; print $result; Does the same than shell_exec() - function
  • 32. Logical Operators $a and $b $a or $b $a xor $b !$a; $a && $b; $a || $b;
  • 33. String Operators Two operators for strings: '.' and '.=' '.' – combining strings. '.=' – appends string to the end. Example: $v= &quot;Hello&quot; . $b; $v.= &quot;Hello&quot;;
  • 34. Arrays See http://php.tpu.fi/~pohjus/lectures/php/php-arrays.html
  • 36. IF <?php if ($a > $b) {    echo &quot;a is bigger than b&quot;; } else {    echo &quot;a is NOT bigger than b&quot;; } if ($a > $b) {    echo &quot;a is bigger than b&quot;; } elseif ($a == $b) {    echo &quot;a is equal to b&quot;; } else {    echo &quot;a is smaller than b&quot;; } ?>
  • 37. While and Do-While <?php $a=0; while($a<10){ print $a; $a++; } $i = 0; do {    print $i; } while ($i > 0); ?>
  • 38. For for ($i = 1; $i <= 10; $i++) {    print $i; }
  • 39. Foreach $arr = array(1, 2, 3, 4); foreach ($arr as $value) {    echo $value; }
  • 40. Switch switch ($i) { case 0:    echo &quot;i equals 0&quot;;    break; case 1:    echo &quot;i equals 1&quot;;    break; case 2:    echo &quot;i equals 2&quot;;    break; }
  • 43. Example: spaghetti-way <!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;> <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;> <head> <title>xhtml-doku</title> <meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /> </head> <body> <h1>Title</h1> <?php print &quot;<p>Hello from PHP!</p>&quot;; ?> </body> </html>
  • 44. Better ways Use functions Use OO
  • 45. PHP AND USER INPUT
  • 46. PHP and User Input via Forms See http://php.tpu.fi/~pohjus/lectures/php/forms-and-php.html