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
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
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
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