SlideShare une entreprise Scribd logo
1  sur  16
Introduction to PHP
www.collaborationtech.co.in
Bengaluru INDIA
Presentation By
Ramananda M.S Rao
Content
Content
Introduction
Get Started
Variables & Data Types
Control Structure
Operators and Expressions
Strings and Arrays
Functions
Local & Global Variables in Functions
Files Handling and Globbing
Exception Handling
References
OOPS Concepts
Collections
Regular Expressions
PHP Utility Programs
Working with HTTP and Browser
Working with MYSQL and PHP
Working with PEAR
Application Development Projects
About Us
www.collaborationtech.co.in
Introduction
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
What is a PHP File?
PHP files can contain text, HTML, CSS, JavaScript, and PHP code
PHP code are executed on the server, and the result is returned to the
browser as plain HTML
PHP files have extension ".php"
www.collaborationtech.co.in
Get Started
<html>
<head>
<title>Hello World</title>
</head>
<body>
<?php
$a="Hello";
$b="World";
echo $a,$b;
?>
</body>
</html>
www.collaborationtech.co.in
Control Structure
 Control structure are usually based on condition and therefore always have condition associated with them
They check the status of these conditions ,which can be either true or false .
<html>
<head><title></title></head>
<body>
<?php
$hour = date( "G" );$year = date( "Y" );
if ( $hour >= 5 && $hour < 12 )
{echo "<h1>Good morning!</h1>";}
elseif( $hour >= 12 && $hour < 18 )
{echo "<h1>Good afternoon!</h1>";}
elseif ( $hour >= 18 && $hour < 22 )
{echo "<h1>Good evening!</h1>";}
Else {echo "<h1>Good night!</h1>";}
$leapYear = false;
if ((( $year % 4 == 0 )&&( $year % 100 != 0))||($year % 400 == 0))
$leapYear = true;
echo "<p>Did you know that $year is" , ( $leapYear ? "" : " not" ) , " a leap
year?</p>";
?>
</body>
</html>
www.collaborationtech.co.in
Control Structure
<html>
<head>
<title> Factorial </title>
</head>
<body>
<h1> Factorial </h1>
<?php
$num=4;
for($i=1;$i<$num;$i++)
{
$fact=1;
for($j=1;$j<=$num;$j++)
{
$fact*=$i*$j;
echo $fact,"<br>";
}
}
?>
</body>
</html>
www.collaborationtech.co.in
Strings
<html>
<head><title>Lower Upper Case</title></head>
<body>
<?php
$myString = "hello, world!";
echo strtolower($myString), "<br>"; // Displays ‘hello, world!’
echo strtoupper($myString), "<br>"; // Displays ‘HELLO, WORLD!’
echo ucfirst($myString), "<br>"; // Displays ‘Hello, world!’
//echo lcfirst($myString), "<br>"; // Displays ‘hello, World!’
echo ucwords($myString), "<br>"; // Displays ‘Hello, World!’
?>
</body>
</html>
www.collaborationtech.co.in
Functions
 PHP functions are similar to other programming languages. A function is a piece of code which takes one more
input in the form of parameter and does some processing and returns a value.
Example:
<html>
<head>
<title> Function </title>
</head>
<body>
<h1> Function </h1>
<?php
function hello()
{echo "Hello, world!<br/>";}
hello();
?>
</body>
</html>
www.collaborationtech.co.in
File Handling
 File handling is a very important part of any web application. Many times you need to open a file and process the
file according to the specific requirement.
Example:
<html>
<head>
<title>Reading a File</title>
</head>
<body>
<?php
$handle=fopen("file.txt","r");
while(!feof($handle))
{
$text=fgets($handle);
echo $text,"<br>";
}
?></body></html>
file.txt
Hello, Collaba.
How r u?
PHP is cool, keep it up..
www.collaborationtech.co.in
File Handling
<html>
<head>
<title>File Exist or Not</title>
</head>
<body>
<?php
$filename="file.txt";
if(file_exists($filename))
{
$data=file($filename);
foreach($data as $number=>$line)
{echo "Line $number: ", $line, "<br>";}}
else
{echo "The file $filename does not exist";}
?>
</body>
</html>
www.collaborationtech.co.in
File Handling
<html>
<head>
<title>Copying File</title>
</head>
<body>
<?php
$file='file.txt';
$copy='filecopy.txt';
if(copy($file,$copy))
{echo "$file is successfuly copied";}
else
{echo "$file could not be copied";}
?>
</body>
</html>
www.collaborationtech.co.in
OOPS
<!DOCTYPE html>
<html lang="en">
<head>
<title> A Simple Car Simulator </title>
<link rel="stylesheet" type="text/css" href="common.css" />
</head>
<body>
<h1> A Simple Car Simulator </h1>
<?php
class Car
{public $color;public $manufacturer;public $model;private $_speed = 0;
public function accelerate()
{if ( $this-> _speed >= 100 ) return false;$this-> _speed += 10;return true;}
public function brake()
{if ( $this-> _speed <= 0 ) return false;$this-> _speed -= 10;return true;}
www.collaborationtech.co.in
OOPS
public function getSpeed()
{return $this-> _speed;}}
$myCar = new Car();
$myCar-> color = "red";
$myCar-> manufacturer = "Volkswagen";
$myCar-> model = "Beetle";
echo " <p> I’m driving a $myCar->color $myCar->manufacturer $myCar->model. </p> ";
echo " <p> Stepping on the gas... <br /> ";
while ( $myCar-> accelerate() )
{echo "Current speed: " . $myCar-> getSpeed() . " mph <br /> ";}
echo " </p> <p> Top speed! Slowing down... <br /> ";
while ( $myCar-> brake() )
{echo "Current speed: " . $myCar-> getSpeed() . " mph <br /> ";}
echo " </p> <p> Stopped! </p> ";
?>
</body>
</html>
www.collaborationtech.co.in
Regular Expressions
 Regular expressions are nothing more than a sequence or pattern of characters itself. They provide
the foundation for pattern-matching functionality.
Example:
<?php
echo preg_match( "/world/", "Hello, world!", $match ), "<br />";
echo $match[0], "<br />";
?>
Example:
<?php
//Code to check the email using Posix compatible regular expression
$pattern = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+.[a-zA-Z.]{2,5}$";
$email = "jim@demo.com";
if (eregi($pattern,$email))
echo "Match";
else
echo "Not match";
?>
www.collaborationtech.co.in
Follow us on Social
Facebook: https://www.facebook.com/collaborationtechnologies/
Twitter : https://twitter.com/collaboration09
Google Plus : https://plus.google.com/100704494006819853579
LinkedIn : https://www.linkedin.com/in/ramananda-rao-a2012545
Instagram : https://instagram.com/collaborationtechnologies
YouTube :
https://www.youtube.com/channel/UCm9nK56LRbWSqcYWbzs8CUg
Skype : facebook:ramananda.rao.7
WhatsApp : +91 9886272445
www.collaborationtech.co.in
THANK YOU
About Us

Contenu connexe

Tendances

JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
Jussi Pohjolainen
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorial
alexjones89
 

Tendances (20)

Php technical presentation
Php technical presentationPhp technical presentation
Php technical presentation
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
 
Html ppt
Html pptHtml ppt
Html ppt
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorial
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Web api
Web apiWeb api
Web api
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
 
PHP Loops and PHP Forms
PHP  Loops and PHP FormsPHP  Loops and PHP Forms
PHP Loops and PHP Forms
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
Eye catching HTML BASICS tips: Learn easily
Eye catching HTML BASICS tips: Learn easilyEye catching HTML BASICS tips: Learn easily
Eye catching HTML BASICS tips: Learn easily
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 

En vedette

Top 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and AnswersTop 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and Answers
Vineet Kumar Saini
 
Top 100 PHP Questions and Answers
Top 100 PHP Questions and AnswersTop 100 PHP Questions and Answers
Top 100 PHP Questions and Answers
iimjobs and hirist
 

En vedette (20)

01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
State of the Word 2011
State of the Word 2011State of the Word 2011
State of the Word 2011
 
Lessons Learned - Building YDN
Lessons Learned - Building YDNLessons Learned - Building YDN
Lessons Learned - Building YDN
 
PHP - Introduction to PHP Functions
PHP -  Introduction to PHP FunctionsPHP -  Introduction to PHP Functions
PHP - Introduction to PHP Functions
 
Introduction to JavaScript Programming
Introduction to JavaScript ProgrammingIntroduction to JavaScript Programming
Introduction to JavaScript Programming
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
100 PHP question and answer
100 PHP  question and answer100 PHP  question and answer
100 PHP question and answer
 
Practice exam php
Practice exam phpPractice exam php
Practice exam php
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
Top 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and AnswersTop 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and Answers
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
Implementing DDD Concepts in PHP
Implementing DDD Concepts in PHPImplementing DDD Concepts in PHP
Implementing DDD Concepts in PHP
 
1000+ php questions
1000+ php questions1000+ php questions
1000+ php questions
 
PHP - Introduction to PHP
PHP -  Introduction to PHPPHP -  Introduction to PHP
PHP - Introduction to PHP
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
Class 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingClass 6 - PHP Web Programming
Class 6 - PHP Web Programming
 
Top 100 PHP Questions and Answers
Top 100 PHP Questions and AnswersTop 100 PHP Questions and Answers
Top 100 PHP Questions and Answers
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 

Similaire à Introduction to PHP

GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
Nat Weerawan
 
Cakefest 2010: API Development
Cakefest 2010: API DevelopmentCakefest 2010: API Development
Cakefest 2010: API Development
Andrew Curioso
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kian
phelios
 

Similaire à Introduction to PHP (20)

PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array.
 
Php with my sql
Php with my sqlPhp with my sql
Php with my sql
 
Php
PhpPhp
Php
 
Introducation to php for beginners
Introducation to php for beginners Introducation to php for beginners
Introducation to php for beginners
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
 
PHP-Part1
PHP-Part1PHP-Part1
PHP-Part1
 
Cakefest 2010: API Development
Cakefest 2010: API DevelopmentCakefest 2010: API Development
Cakefest 2010: API Development
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Intro to php
Intro to phpIntro to php
Intro to php
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Basic php 5
Basic php 5Basic php 5
Basic php 5
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
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
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kian
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 

Plus de Collaboration Technologies

Plus de Collaboration Technologies (15)

Introduction to Core Java Programming
Introduction to Core Java ProgrammingIntroduction to Core Java Programming
Introduction to Core Java Programming
 
Introduction to Database SQL & PL/SQL
Introduction to Database SQL & PL/SQLIntroduction to Database SQL & PL/SQL
Introduction to Database SQL & PL/SQL
 
Introduction to Advanced Javascript
Introduction to Advanced JavascriptIntroduction to Advanced Javascript
Introduction to Advanced Javascript
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to Bootstrap
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
 
Introduction to HTML4
Introduction to HTML4Introduction to HTML4
Introduction to HTML4
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
Introduction to JPA Framework
Introduction to JPA FrameworkIntroduction to JPA Framework
Introduction to JPA Framework
 
Introduction to Perl Programming
Introduction to Perl ProgrammingIntroduction to Perl Programming
Introduction to Perl Programming
 
Introduction to Python Basics Programming
Introduction to Python Basics ProgrammingIntroduction to Python Basics Programming
Introduction to Python Basics Programming
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Introduction to Struts 2
Introduction to Struts 2Introduction to Struts 2
Introduction to Struts 2
 
Introduction to JSON & AJAX
Introduction to JSON & AJAXIntroduction to JSON & AJAX
Introduction to JSON & AJAX
 
Introduction to Node.JS
Introduction to Node.JSIntroduction to Node.JS
Introduction to Node.JS
 

Dernier

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
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
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

Introduction to PHP

  • 1. Introduction to PHP www.collaborationtech.co.in Bengaluru INDIA Presentation By Ramananda M.S Rao
  • 2. Content Content Introduction Get Started Variables & Data Types Control Structure Operators and Expressions Strings and Arrays Functions Local & Global Variables in Functions Files Handling and Globbing Exception Handling References OOPS Concepts Collections Regular Expressions PHP Utility Programs Working with HTTP and Browser Working with MYSQL and PHP Working with PEAR Application Development Projects About Us www.collaborationtech.co.in
  • 3. Introduction 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 What is a PHP File? PHP files can contain text, HTML, CSS, JavaScript, and PHP code PHP code are executed on the server, and the result is returned to the browser as plain HTML PHP files have extension ".php" www.collaborationtech.co.in
  • 5. Control Structure  Control structure are usually based on condition and therefore always have condition associated with them They check the status of these conditions ,which can be either true or false . <html> <head><title></title></head> <body> <?php $hour = date( "G" );$year = date( "Y" ); if ( $hour >= 5 && $hour < 12 ) {echo "<h1>Good morning!</h1>";} elseif( $hour >= 12 && $hour < 18 ) {echo "<h1>Good afternoon!</h1>";} elseif ( $hour >= 18 && $hour < 22 ) {echo "<h1>Good evening!</h1>";} Else {echo "<h1>Good night!</h1>";} $leapYear = false; if ((( $year % 4 == 0 )&&( $year % 100 != 0))||($year % 400 == 0)) $leapYear = true; echo "<p>Did you know that $year is" , ( $leapYear ? "" : " not" ) , " a leap year?</p>"; ?> </body> </html> www.collaborationtech.co.in
  • 6. Control Structure <html> <head> <title> Factorial </title> </head> <body> <h1> Factorial </h1> <?php $num=4; for($i=1;$i<$num;$i++) { $fact=1; for($j=1;$j<=$num;$j++) { $fact*=$i*$j; echo $fact,"<br>"; } } ?> </body> </html> www.collaborationtech.co.in
  • 7. Strings <html> <head><title>Lower Upper Case</title></head> <body> <?php $myString = "hello, world!"; echo strtolower($myString), "<br>"; // Displays ‘hello, world!’ echo strtoupper($myString), "<br>"; // Displays ‘HELLO, WORLD!’ echo ucfirst($myString), "<br>"; // Displays ‘Hello, world!’ //echo lcfirst($myString), "<br>"; // Displays ‘hello, World!’ echo ucwords($myString), "<br>"; // Displays ‘Hello, World!’ ?> </body> </html> www.collaborationtech.co.in
  • 8. Functions  PHP functions are similar to other programming languages. A function is a piece of code which takes one more input in the form of parameter and does some processing and returns a value. Example: <html> <head> <title> Function </title> </head> <body> <h1> Function </h1> <?php function hello() {echo "Hello, world!<br/>";} hello(); ?> </body> </html> www.collaborationtech.co.in
  • 9. File Handling  File handling is a very important part of any web application. Many times you need to open a file and process the file according to the specific requirement. Example: <html> <head> <title>Reading a File</title> </head> <body> <?php $handle=fopen("file.txt","r"); while(!feof($handle)) { $text=fgets($handle); echo $text,"<br>"; } ?></body></html> file.txt Hello, Collaba. How r u? PHP is cool, keep it up.. www.collaborationtech.co.in
  • 10. File Handling <html> <head> <title>File Exist or Not</title> </head> <body> <?php $filename="file.txt"; if(file_exists($filename)) { $data=file($filename); foreach($data as $number=>$line) {echo "Line $number: ", $line, "<br>";}} else {echo "The file $filename does not exist";} ?> </body> </html> www.collaborationtech.co.in
  • 11. File Handling <html> <head> <title>Copying File</title> </head> <body> <?php $file='file.txt'; $copy='filecopy.txt'; if(copy($file,$copy)) {echo "$file is successfuly copied";} else {echo "$file could not be copied";} ?> </body> </html> www.collaborationtech.co.in
  • 12. OOPS <!DOCTYPE html> <html lang="en"> <head> <title> A Simple Car Simulator </title> <link rel="stylesheet" type="text/css" href="common.css" /> </head> <body> <h1> A Simple Car Simulator </h1> <?php class Car {public $color;public $manufacturer;public $model;private $_speed = 0; public function accelerate() {if ( $this-> _speed >= 100 ) return false;$this-> _speed += 10;return true;} public function brake() {if ( $this-> _speed <= 0 ) return false;$this-> _speed -= 10;return true;} www.collaborationtech.co.in
  • 13. OOPS public function getSpeed() {return $this-> _speed;}} $myCar = new Car(); $myCar-> color = "red"; $myCar-> manufacturer = "Volkswagen"; $myCar-> model = "Beetle"; echo " <p> I’m driving a $myCar->color $myCar->manufacturer $myCar->model. </p> "; echo " <p> Stepping on the gas... <br /> "; while ( $myCar-> accelerate() ) {echo "Current speed: " . $myCar-> getSpeed() . " mph <br /> ";} echo " </p> <p> Top speed! Slowing down... <br /> "; while ( $myCar-> brake() ) {echo "Current speed: " . $myCar-> getSpeed() . " mph <br /> ";} echo " </p> <p> Stopped! </p> "; ?> </body> </html> www.collaborationtech.co.in
  • 14. Regular Expressions  Regular expressions are nothing more than a sequence or pattern of characters itself. They provide the foundation for pattern-matching functionality. Example: <?php echo preg_match( "/world/", "Hello, world!", $match ), "<br />"; echo $match[0], "<br />"; ?> Example: <?php //Code to check the email using Posix compatible regular expression $pattern = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+.[a-zA-Z.]{2,5}$"; $email = "jim@demo.com"; if (eregi($pattern,$email)) echo "Match"; else echo "Not match"; ?> www.collaborationtech.co.in
  • 15. Follow us on Social Facebook: https://www.facebook.com/collaborationtechnologies/ Twitter : https://twitter.com/collaboration09 Google Plus : https://plus.google.com/100704494006819853579 LinkedIn : https://www.linkedin.com/in/ramananda-rao-a2012545 Instagram : https://instagram.com/collaborationtechnologies YouTube : https://www.youtube.com/channel/UCm9nK56LRbWSqcYWbzs8CUg Skype : facebook:ramananda.rao.7 WhatsApp : +91 9886272445 www.collaborationtech.co.in THANK YOU