SlideShare ist ein Scribd-Unternehmen logo
1 von 51
Downloaden Sie, um offline zu lesen
iFour ConsultancyPHP
HYPERTEXT PREPROCESSOR
web Engineering ||
winter 2017
wahidullah Mudaser
assignment.cs2017@gmail.com
 Lecture 05
 Introduction To PHP
 Three-tiered website
 Introduction to PHP
 Server side scripting langauge
INDEX
http://www.ifourtechnolab.com/ ASP.NET Software Development Companies India
Three-tiered Web Site
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
Server Side Scripting Language
 A “script” is a collection of program or sequence of instructions that is interpreted or carried out
by another program rather than by the computer processor.
 Client-side
 Server-side
 In server-side scripting, (such as PHP, ASP) the script is processed by the server Like: Apache,
ColdFusion, ISAPI and Microsoft's IIS on Windows.
 Client-side scripting such as JavaScript runs on the web browser.
Advantages of Server side Scripting Language
 Dynamic content.
 Computational capability.
 Database and file system access.
 Network access (from the server only).
 Built-in libraries and functions.
 Known platform for execution (as opposed to client-side,
 where the platform is uncontrolled.)
 Security improvements
What Is PHP?
 PHP is a server scripting language, and a powerful tool for making dynamic and interactive
Web pages.
 PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's
ASP.
 PHP is an acronym for "PHP: Hypertext Preprocessor"
 PHP is a widely-used, open source scripting language
 PHP scripts are executed on the server
 PHP is free to download and use
Cont…
 PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
 PHP is compatible with almost all servers used today (Apache, IIS, etc.)
 PHP supports a wide range of databases
 PHP is free. Download it from the official PHP resource: www.php.net
 PHP is easy to learn and runs efficiently on the server side
Brief History of PHP
PHP (PHP: Hypertext Preprocessor) was created by Rasmus Lerdorf in 1994. It was initially developed for HTTP usage logging and server-
side form generation in Unix.
PHP 2 (1995) transformed the language into a Server-side embedded scripting language. Added database support, file uploads, variables,
arrays, recursive functions, conditionals, iteration, regular expressions, etc.
PHP 3 (1998) added support for ODBC data sources, multiple platform support, email protocols (SNMP,IMAP), and new parser written by
Zeev Suraski and Andi Gutmans .
PHP 4 (2000) became an independent component of the web server for added efficiency. The parser was renamed the Zend Engine. Many
security features were added.
PHP 5 (2004) adds Zend Engine II with object oriented programming, robust XML support using the libxml2 library, SOAP extension for
interoperability with Web Services, SQLite has been bundled with PHP
What is PHP File
PHP files have a file extension of ".php", ".php3", or ".phtml“
 PHP files can contain text, HTML tags and scripts
 PHP files are returned to the browser as plain HTML
Basic PHP Syntax
 A PHP script can be placed anywhere in the document.
 A PHP script starts with <?php and ends with ?>
 <!DOCTYPE html>
<html>
<body>
<h1>PHP TUTORIAL</h1>
<?php
echo “YCCE NAGPUR”;
?>
</body>
</html>
PHP Variables
 A variable starts with the $ sign, followed by the name of
the variable
 A variable name must start with a letter or the
underscore character
 A variable name cannot start with a number
 A variable name can only contain alpha-numeric
characters and underscores (A-z, 0-9, and _ )
 Variable names are case-sensitive ($age and $AGE are
two different variables)
Basic PHP Syntax
<!DOCTYPE html>
<html>
<body>
<?php
// This is a single-line comment
# This is also a single-line comment
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
// You can also use comments to leave out parts of a code line
$x = 5 /* + 15 */ + 5;
echo $x;
?>
</body>
</html>
PHP is Loosely Typed language
 In the example above, notice that we did not have to tell
PHP which data type the variable is.
 PHP automatically converts the variable to the correct
data type, depending on its value.
 In other languages such as C, C++, and Java, the
programmer must declare the name and type of the
variable before using it.
PHP Variables 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
PHP global keyword
 The global keyword is used to access a global variable from within a
function.
 To do this, use the global keyword before the variables
<?php
$x = 5;
$y = 10;
function myTest() {
global $x, $y;
$y = $x + $y;
}
myTest();
echo $y;
?>
PHP Static Keyword
 <?php
function myTest() {
static $x = 0;
echo $x;
$x++;
}
myTest();
myTest();
myTest();
?>
PHP echo Statement
<?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with multiple
parameters.";
?>
PHP print statement
<?php
$txt1 = "Learn PHP";
$txt2 = “ycce.com";
$x = 5;
$y = 4;
print "<h2>$txt1</h2>";
print "Study PHP at $txt2<br>";
print $x + $y;
?>
Echo V.S Print
 The differences are small: echo has no return value while
print has a return value of 1 so it can be used in expressions.
 echo can take multiple parameters (although such usage is
rare) while print can take one argument.
 echo is marginally faster than print.
PHP Data types
 PHP supports the following data types:
 String
 Integer
 Float (floating point numbers - also called double)
 Boolean
 Array
 Object
 NULL
 Resource
Data types cont..
PHP String:
 A string is a sequence of characters, like "Hello world!".
 A string can be any text inside quotes. You can use single
or double quotes:
Example
<?php
$x = 5985;
var_dump($x);
?>
Cont…
PHP Array:
<?php
$cars = array("Volvo","BMW","Toyota");
var_dump($cars);
?>
PHP Object
 An object is a data type which stores data and information on
how to process that data.
 In PHP, an object must be explicitly declared.
<?php
class Car {
function Car() {
$this->model = "VW";
}
}
// create an object
$herbie = new Car();
// show object properties
echo $herbie->model;
?>
PHP NULL value
 Null is a special data type which can have only one value:
NULL.
 A variable of data type NULL is a variable that has no
value assigned to it.
 Note: If a variable is created without a value, it is
automatically assigned a value of NULL.
Example
<?php
$x = "Hello world!";
$x = null;
var_dump($x);
?>
PHP String Functions
Get The Length of a String:
 The PHP strlen() function returns the length of a string
(number of characters).
 The example below returns the length of the string "Hello
world!":
Example
<?php
echo strlen("Hello world!"); // outputs 12
?>
Cont…
Count The Number of Words in a String:
Example
<?php
echo str_word_count("Hello world!"); // outputs 2
?>
Reverse a String:
Example
<?php
echo strrev("Hello world!");
?>
Cont…
Search For a Specific Text Within a String:
 If a match is found, the function returns the character
position of the first match. If no match is found, it will
return FALSE.
Example
<?php
echo strpos("Hello world!", "world"); // outputs 6
?>
Cont…
 Replace Text Within a String:
Example
<?php
echo str_replace("world", "Dolly", "Hello world!"); //
outputs Hello Dolly!
?>
PHP Constants
 A constant is an identifier (name) for a simple value. The value cannot
be changed during the script.
 A valid constant name starts with a letter or underscore (no $ sign
before the constant name).
 Note: Unlike variables, constants are automatically global across the
entire script.
PHP Constants
Syntax:
define(name, value, case-insensitive)
Parameters:
 name: Specifies the name of the constant
 value: Specifies the value of the constant
 case-insensitive: Specifies whether the constant name should be case-insensitive.
Default is false
Example - Constants
<?php
define(“NAME", "Welcome Ahmadullah!");
echo NAME;
?>
Constants are Global:
<?php
define(“NAME", "Welcome Ahmadullah!");
function myTest() {
echo NAME;
}
myTest();
?>
PHP Operators
Operators are used to perform operations on variables and
values.
PHP divides the operators in the following groups:
 Arithmetic operators
 Assignment operators
 Comparison operators
 Increment/Decrement operators
 Logical operators
 String operators
 Array operators
PHP Operators
PHP Arithmetic Operators:
PHP Operators
PHP Assignment Operators:
PHP Operators
PHP Comparison Operators:
PHP Operators
PHP Increment / Decrement Operators:
PHP Operators
PHP Logical Operators:
PHP Operators
PHP String Operators:
PHP Operators
PHP Array Operators:
PHP Conditional Statements
 In PHP we have the following conditional statements:
 if statement - executes some code only if a specified
condition is true
 if...else statement - executes some code if a condition is
true and another code if the condition is false
 if...elseif....else statement - specifies a new condition to
test, if the first condition is false
 switch statement - selects one of many blocks of code to
be executed
PHP – The IF Statement
 The if statement is used to execute some code only if a
specified condition is true.
Syntax
if (condition)
{
code to be executed if condition is true;
}
PHP - The if...else Statement
 Use the if....else statement to execute some code if a
condition is true and another code if the condition is
false.
Syntax:
if (condition) {
code to be executed if condition is true;
} else {
code to be executed if condition is false;
}
PHP - The if...elseif....else Statement
 Use the if....elseif...else statement to specify a new
condition to test, if the first condition is false.
Syntax:
if (condition) {
code to be executed if condition is true;
} elseif (condition) {
code to be executed if condition is true;
} else {
code to be executed if condition is false;
}
PHP - The switch Statement
 Use the switch statement to select one of many blocks of
code to be executed.
Syntax:
switch (n) {
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
case label3:
code to be executed if n=label3;
break;
...
default:
code to be executed if n is different from all labels;
}
PHP Loops
In PHP, we have the following looping statements:
 while - loops through a block of code as long as the
specified condition is true
 do...while - loops through a block of code once, and then
repeats the loop as long as the specified condition is true
 for - loops through a block of code a specified number of
times
 foreach - loops through a block of code for each element
in an array
While Loops
 The while loop executes a block of code as long as the
specified condition is true.
Syntax:
while (condition is true)
{
code to be executed;
}
Do…while loop
 The do...while loop will always execute the block of code
once, it will then check the condition, and repeat the loop
while the specified condition is true.
Syntax:
do {
code to be executed;
}
while (condition is true);
For Loop
 The for loop is used when you know in advance how
many times the script should run.
Syntax:
for (init counter; test counter; increment counter)
{
code to be executed;
}
Foreach Loop
 The foreach loop works only on arrays, and is used to
loop through each key/value pair in an array.
Syntax:
foreach ($array as $value)
{
code to be executed;
}
Example – foreach loop
 For every loop iteration, the value of the current array
element is assigned to $value and the array pointer is
moved by one, until it reaches the last array element.
Example:
<?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
?>
PHP Functions
PHP User Defined Functions
 Besides the built-in PHP functions, we can create our own
functions.
 A function is a block of statements that can be used
repeatedly in a program.
 A function will not execute immediately when a page
loads.
 A function will be executed by a call to the function.
Questions?
http://www.ifourtechnolab.com/ ASP.NET Software Development Companies India

Weitere ähnliche Inhalte

Was ist angesagt? (20)

PHP
PHPPHP
PHP
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
Class and Objects in PHP
Class and Objects in PHPClass and Objects in PHP
Class and Objects in PHP
 
PHP slides
PHP slidesPHP slides
PHP slides
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
Php forms
Php formsPhp forms
Php forms
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
 
01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
 
laravel.pptx
laravel.pptxlaravel.pptx
laravel.pptx
 
Php cookies
Php cookiesPhp cookies
Php cookies
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
Javascript
JavascriptJavascript
Javascript
 
Php tutorial
Php  tutorialPhp  tutorial
Php tutorial
 
Html ppt
Html pptHtml ppt
Html ppt
 

Ähnlich wie Introduction to PHP - Basics of PHP

FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQLArti Parab Academics
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Gheyath M. Othman
 
Php by shivitomer
Php by shivitomerPhp by shivitomer
Php by shivitomerShivi Tomer
 
1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_masterjeeva indra
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive OverviewMohamed Loey
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPtutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPtutorialsruby
 
Introduction to PHP.ppt
Introduction to PHP.pptIntroduction to PHP.ppt
Introduction to PHP.pptSanthiNivas
 
Php tutorial from_beginner_to_master
Php tutorial from_beginner_to_masterPhp tutorial from_beginner_to_master
Php tutorial from_beginner_to_masterPrinceGuru MS
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...anshkhurana01
 

Ähnlich wie Introduction to PHP - Basics of PHP (20)

FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Php by shivitomer
Php by shivitomerPhp by shivitomer
Php by shivitomer
 
1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
PHP-Part1
PHP-Part1PHP-Part1
PHP-Part1
 
Materi Dasar PHP
Materi Dasar PHPMateri Dasar PHP
Materi Dasar PHP
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Introduction to PHP.ppt
Introduction to PHP.pptIntroduction to PHP.ppt
Introduction to PHP.ppt
 
Php tutorial from_beginner_to_master
Php tutorial from_beginner_to_masterPhp tutorial from_beginner_to_master
Php tutorial from_beginner_to_master
 
PHP Basic & Variables
PHP Basic & VariablesPHP Basic & Variables
PHP Basic & Variables
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
 

Mehr von wahidullah mudaser

Mehr von wahidullah mudaser (6)

AJAX-Asynchronous JavaScript and XML
AJAX-Asynchronous JavaScript and XMLAJAX-Asynchronous JavaScript and XML
AJAX-Asynchronous JavaScript and XML
 
XML - Extensive Markup Language
XML - Extensive Markup LanguageXML - Extensive Markup Language
XML - Extensive Markup Language
 
PHP file handling
PHP file handling PHP file handling
PHP file handling
 
Object Oriented Programming in PHP
Object Oriented Programming  in PHPObject Oriented Programming  in PHP
Object Oriented Programming in PHP
 
PHP with MySQL
PHP with MySQLPHP with MySQL
PHP with MySQL
 
PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array.
 

Kürzlich hochgeladen

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Kürzlich hochgeladen (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Introduction to PHP - Basics of PHP

  • 1. iFour ConsultancyPHP HYPERTEXT PREPROCESSOR web Engineering || winter 2017 wahidullah Mudaser assignment.cs2017@gmail.com  Lecture 05  Introduction To PHP
  • 2.  Three-tiered website  Introduction to PHP  Server side scripting langauge INDEX http://www.ifourtechnolab.com/ ASP.NET Software Development Companies India
  • 3. Three-tiered Web Site 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. Server Side Scripting Language  A “script” is a collection of program or sequence of instructions that is interpreted or carried out by another program rather than by the computer processor.  Client-side  Server-side  In server-side scripting, (such as PHP, ASP) the script is processed by the server Like: Apache, ColdFusion, ISAPI and Microsoft's IIS on Windows.  Client-side scripting such as JavaScript runs on the web browser.
  • 5. Advantages of Server side Scripting Language  Dynamic content.  Computational capability.  Database and file system access.  Network access (from the server only).  Built-in libraries and functions.  Known platform for execution (as opposed to client-side,  where the platform is uncontrolled.)  Security improvements
  • 6. What Is PHP?  PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.  PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.  PHP is an acronym for "PHP: Hypertext Preprocessor"  PHP is a widely-used, open source scripting language  PHP scripts are executed on the server  PHP is free to download and use
  • 7. Cont…  PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)  PHP is compatible with almost all servers used today (Apache, IIS, etc.)  PHP supports a wide range of databases  PHP is free. Download it from the official PHP resource: www.php.net  PHP is easy to learn and runs efficiently on the server side
  • 8. Brief History of PHP PHP (PHP: Hypertext Preprocessor) was created by Rasmus Lerdorf in 1994. It was initially developed for HTTP usage logging and server- side form generation in Unix. PHP 2 (1995) transformed the language into a Server-side embedded scripting language. Added database support, file uploads, variables, arrays, recursive functions, conditionals, iteration, regular expressions, etc. PHP 3 (1998) added support for ODBC data sources, multiple platform support, email protocols (SNMP,IMAP), and new parser written by Zeev Suraski and Andi Gutmans . PHP 4 (2000) became an independent component of the web server for added efficiency. The parser was renamed the Zend Engine. Many security features were added. PHP 5 (2004) adds Zend Engine II with object oriented programming, robust XML support using the libxml2 library, SOAP extension for interoperability with Web Services, SQLite has been bundled with PHP
  • 9. What is PHP File PHP files have a file extension of ".php", ".php3", or ".phtml“  PHP files can contain text, HTML tags and scripts  PHP files are returned to the browser as plain HTML
  • 10. Basic PHP Syntax  A PHP script can be placed anywhere in the document.  A PHP script starts with <?php and ends with ?>  <!DOCTYPE html> <html> <body> <h1>PHP TUTORIAL</h1> <?php echo “YCCE NAGPUR”; ?> </body> </html>
  • 11. PHP Variables  A variable starts with the $ sign, followed by the name of the variable  A variable name must start with a letter or the underscore character  A variable name cannot start with a number  A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )  Variable names are case-sensitive ($age and $AGE are two different variables)
  • 12. Basic PHP Syntax <!DOCTYPE html> <html> <body> <?php // This is a single-line comment # This is also a single-line comment /* This is a multiple-lines comment block that spans over multiple lines */ // You can also use comments to leave out parts of a code line $x = 5 /* + 15 */ + 5; echo $x; ?> </body> </html>
  • 13. PHP is Loosely Typed language  In the example above, notice that we did not have to tell PHP which data type the variable is.  PHP automatically converts the variable to the correct data type, depending on its value.  In other languages such as C, C++, and Java, the programmer must declare the name and type of the variable before using it.
  • 14. PHP Variables 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
  • 15. PHP global keyword  The global keyword is used to access a global variable from within a function.  To do this, use the global keyword before the variables <?php $x = 5; $y = 10; function myTest() { global $x, $y; $y = $x + $y; } myTest(); echo $y; ?>
  • 16. PHP Static Keyword  <?php function myTest() { static $x = 0; echo $x; $x++; } myTest(); myTest(); myTest(); ?>
  • 17. PHP echo Statement <?php echo "<h2>PHP is Fun!</h2>"; echo "Hello world!<br>"; echo "I'm about to learn PHP!<br>"; echo "This ", "string ", "was ", "made ", "with multiple parameters."; ?>
  • 18. PHP print statement <?php $txt1 = "Learn PHP"; $txt2 = “ycce.com"; $x = 5; $y = 4; print "<h2>$txt1</h2>"; print "Study PHP at $txt2<br>"; print $x + $y; ?> Echo V.S Print  The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions.  echo can take multiple parameters (although such usage is rare) while print can take one argument.  echo is marginally faster than print.
  • 19. PHP Data types  PHP supports the following data types:  String  Integer  Float (floating point numbers - also called double)  Boolean  Array  Object  NULL  Resource
  • 20. Data types cont.. PHP String:  A string is a sequence of characters, like "Hello world!".  A string can be any text inside quotes. You can use single or double quotes: Example <?php $x = 5985; var_dump($x); ?>
  • 21. Cont… PHP Array: <?php $cars = array("Volvo","BMW","Toyota"); var_dump($cars); ?>
  • 22. PHP Object  An object is a data type which stores data and information on how to process that data.  In PHP, an object must be explicitly declared. <?php class Car { function Car() { $this->model = "VW"; } } // create an object $herbie = new Car(); // show object properties echo $herbie->model; ?>
  • 23. PHP NULL value  Null is a special data type which can have only one value: NULL.  A variable of data type NULL is a variable that has no value assigned to it.  Note: If a variable is created without a value, it is automatically assigned a value of NULL. Example <?php $x = "Hello world!"; $x = null; var_dump($x); ?>
  • 24. PHP String Functions Get The Length of a String:  The PHP strlen() function returns the length of a string (number of characters).  The example below returns the length of the string "Hello world!": Example <?php echo strlen("Hello world!"); // outputs 12 ?>
  • 25. Cont… Count The Number of Words in a String: Example <?php echo str_word_count("Hello world!"); // outputs 2 ?> Reverse a String: Example <?php echo strrev("Hello world!"); ?>
  • 26. Cont… Search For a Specific Text Within a String:  If a match is found, the function returns the character position of the first match. If no match is found, it will return FALSE. Example <?php echo strpos("Hello world!", "world"); // outputs 6 ?>
  • 27. Cont…  Replace Text Within a String: Example <?php echo str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly! ?>
  • 28. PHP Constants  A constant is an identifier (name) for a simple value. The value cannot be changed during the script.  A valid constant name starts with a letter or underscore (no $ sign before the constant name).  Note: Unlike variables, constants are automatically global across the entire script.
  • 29. PHP Constants Syntax: define(name, value, case-insensitive) Parameters:  name: Specifies the name of the constant  value: Specifies the value of the constant  case-insensitive: Specifies whether the constant name should be case-insensitive. Default is false
  • 30. Example - Constants <?php define(“NAME", "Welcome Ahmadullah!"); echo NAME; ?> Constants are Global: <?php define(“NAME", "Welcome Ahmadullah!"); function myTest() { echo NAME; } myTest(); ?>
  • 31. PHP Operators Operators are used to perform operations on variables and values. PHP divides the operators in the following groups:  Arithmetic operators  Assignment operators  Comparison operators  Increment/Decrement operators  Logical operators  String operators  Array operators
  • 35. PHP Operators PHP Increment / Decrement Operators:
  • 39. PHP Conditional Statements  In PHP we have the following conditional statements:  if statement - executes some code only if a specified condition is true  if...else statement - executes some code if a condition is true and another code if the condition is false  if...elseif....else statement - specifies a new condition to test, if the first condition is false  switch statement - selects one of many blocks of code to be executed
  • 40. PHP – The IF Statement  The if statement is used to execute some code only if a specified condition is true. Syntax if (condition) { code to be executed if condition is true; }
  • 41. PHP - The if...else Statement  Use the if....else statement to execute some code if a condition is true and another code if the condition is false. Syntax: if (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; }
  • 42. PHP - The if...elseif....else Statement  Use the if....elseif...else statement to specify a new condition to test, if the first condition is false. Syntax: if (condition) { code to be executed if condition is true; } elseif (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; }
  • 43. PHP - The switch Statement  Use the switch statement to select one of many blocks of code to be executed. Syntax: switch (n) { case label1: code to be executed if n=label1; break; case label2: code to be executed if n=label2; break; case label3: code to be executed if n=label3; break; ... default: code to be executed if n is different from all labels; }
  • 44. PHP Loops In PHP, we have the following looping statements:  while - loops through a block of code as long as the specified condition is true  do...while - loops through a block of code once, and then repeats the loop as long as the specified condition is true  for - loops through a block of code a specified number of times  foreach - loops through a block of code for each element in an array
  • 45. While Loops  The while loop executes a block of code as long as the specified condition is true. Syntax: while (condition is true) { code to be executed; }
  • 46. Do…while loop  The do...while loop will always execute the block of code once, it will then check the condition, and repeat the loop while the specified condition is true. Syntax: do { code to be executed; } while (condition is true);
  • 47. For Loop  The for loop is used when you know in advance how many times the script should run. Syntax: for (init counter; test counter; increment counter) { code to be executed; }
  • 48. Foreach Loop  The foreach loop works only on arrays, and is used to loop through each key/value pair in an array. Syntax: foreach ($array as $value) { code to be executed; }
  • 49. Example – foreach loop  For every loop iteration, the value of the current array element is assigned to $value and the array pointer is moved by one, until it reaches the last array element. Example: <?php $colors = array("red", "green", "blue", "yellow"); foreach ($colors as $value) { echo "$value <br>"; } ?>
  • 50. PHP Functions PHP User Defined Functions  Besides the built-in PHP functions, we can create our own functions.  A function is a block of statements that can be used repeatedly in a program.  A function will not execute immediately when a page loads.  A function will be executed by a call to the function.