KEMBAR78
Introduction to PHP | PPTX
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

Introduction to PHP

  • 1.
    Introduction to PHP www.collaborationtech.co.in BengaluruINDIA 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 anacronym 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
  • 4.
  • 5.
    Control Structure  Controlstructure 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 functionsare 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  Filehandling 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 Existor 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  Regularexpressions 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 onSocial 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
  • 16.