SlideShare a Scribd company logo
UNIT 4- PHP & XML
CS8651 - INTERNET
PROGRAMMING
• An introduction to PHP: PHP- Using PHP- Variables- Program
control- Built-in functions- Form Validation- Regular Expressions -
File handling – Cookies - Connecting to Database.
• XML: Basic XML- Document Type Definition- XML Schema
DOM and Presenting XML, XML
• Parsers and Validation, XSL and XSLT Transformation, News Feed
(RSS and ATOM).
UNIT IV: SYLLABUS
AN INTRODUCTION TO PHP
• PHP is an open-source, interpreted, and object-oriented scripting
language that can be executed at the server-side.
• PHP is well suited for web development.
• PHP stands for Hypertext Pre-processor.
• PHP is an interpreted language, i.e., there is no need for
compilation.
• PHP is faster than other scripting languages, for example, ASP and
JSP.
PHP
• PHP is a server-side scripting language, which is used to manage
the dynamic content of the website.
• PHP can be embedded into HTML.
• PHP is an object-oriented language.
• PHP is an open-source scripting language.
• PHP is simple and easy to learn language.
PHP
• PHP is a server-side scripting language, which is used to design the
dynamic web applications with MySQL database.
– It handles dynamic content, database as well as session tracking
for the website.
– You can create sessions in PHP.
– It can access cookies variable and also set cookies.
– It helps to encrypt the data and apply validation.
– PHP supports several protocols such as HTTP, POP3, SNMP,
LDAP, IMAP, and many more.
WHY USE PHP?
– Using PHP language, you can control the user to access some
pages of your website.
– As PHP is easy to install and set up, this is the main reason why
PHP is the best language to learn.
– PHP can handle the forms, such as - collect the data from users
using forms, save it into the database, and return useful
information to the user. For example - Registration form.
WHY USE PHP?
PHP FEATURES
• How to install XAMPP server on windows -
https://www.apachefriends.org/download.html
INSTALL PHP
• After downloading XAMPP, double click on the downloaded file
and allow XAMPP to make changes in your system. A window will
pop-up, where you have to click on the Next button.
INSTALL PHP
• XAMPP is ready to use. Start the Apache server and MySQL and
run the php program on the localhost.
INSTALL PHP
• If no error is shown, then XAMPP is running successfully.
INSTALL PHP
• PHP programs can be written on any editor, such as - Notepad,
Notepad++, Dreamweaver, etc.
• These programs save with .php extension, i.e., filename.php inside
the htdocs folder.
• Step 1: Create a simple PHP program like hello world.
<!DOCTYPE html>
<html>
<body>
<h1>PHP</h1>
<?php
echo "Hello World";
?>
</body></html>
RUN PHP CODE IN XAMPP
• Step 2: Save the file with hello.php name in the htdocs folder,
which resides inside the xampp folder.
• Step 3: Run the XAMPP server and start the Apache and MySQL.
• Step 4: Now, open the web browser and type localhost
– http://localhost/hello.php on your browser window.
RUN PHP CODE IN XAMPP
• In PHP, keyword (e.g., echo, if, else, while), functions, user-
defined functions, classes are not case-sensitive.
• However, all variable names are case-sensitive.
PHP - CASE SENSITIVE
• A variable is a name given to a memory location that stores data at
runtime.
• The scope of a variable determines its visibility.
• The rules followed when creating variables in PHP
– All variable names must start with the dollar sign.
– Variable names are case sensitive;
– All variables names must start with a letter follow other
characters
– Variable names must not contain any spaces
PHP - VARIABLE
ARITHMETIC OPERATORS
ASSIGNMENT OPERATORS
COMPARISON OPERATORS
LOGICAL OPERATORS
• A function is a block of statements that can be used repeatedly in a
program.
• A function is a self-contained block of code that performs a
specific task.
• A function is a piece of code which takes one or more input in the
form of parameter and does some processing and returns a value.
PHP FUNCTIONS
• Better code organization
– PHP functions allow us to group blocks of related code that
perform a specific task together.
• Reusability
– Once defined, a function can be called by a number of scripts in
our PHP files. This saves us time of reinventing the wheel when
we want to perform some routine tasks such as connecting to
the database
• Easy maintenance
– Updates to the system only need to be made in one place.
WHY USE PHP FUNCTIONS?
• An HTML form contains various input fields such as text box,
checkbox, radio buttons, submit button, and checklist, etc.
• These input fields need to be validated, which ensures that the user
has entered information in all the required fields and also validates
that the information provided by the user is valid and correct.
• There are two types of validation are available in PHP.
• Client-Side Validation − Validation is performed on the client
machine web browsers.
• Server Side Validation − After submitted by data, the data has sent
to a server and perform validation checks in server machine.
FORM VALIDATION
• The things need to be validate are as follows:
– Empty String
– Validate String
– Validate Numbers
– Validate Email
– Validate URL
– Input length
FORM VALIDATION
• A regular expression is a sequence of characters that forms a
search pattern.
• When you search for data in a text, you can use this search pattern
to describe what you are searching for.
• A regular expression can be a single character, or a more
complicated pattern.
• Regular expressions can be used to perform all types of text search
and text replace operations.
REGULAR EXPRESSION
• In PHP, regular expressions are strings composed of delimiters, a
pattern and optional modifiers.
• In the example above, / is the delimiter, w3schools is
the pattern that is being searched for, and i is a modifier that
makes the search case-insensitive.
REGULAR EXPRESSION - SYNTAX
• Modifiers can change how a search is performed.
REGULAR EXPRESSION - MODIFIERS
• PHP supports file handling which is used to read, write and append
data to the file.
• Basic file handling steps
– Opening a file fopen()
– Reading a file fclose()
– Writing a file fread()
– Closing a file fwrite()
– Delete File unlink()
FILE HANDLING
• PHP fopen() function is used to open file or URL and returns
resource.
• The fopen() function accepts two arguments: $filename and
$mode.
• The $filename represents the file to be opended and $mode
represents the file mode for example read-only, read-write, write-
only etc.
fopen()
Modes Description
r Open a file for read only. File pointer starts at the beginning of the file
w Open a file for write only. Erases the contents of the file or creates a new file
if it doesn't exist. File pointer starts at the beginning of the file
a Open a file for write only. The existing data in file is preserved. File pointer
starts at the end of the file. Creates a new file if the file doesn't exist
x Creates a new file for write only. Returns FALSE and an error if file already
exists
r+ Open a file for read/write. File pointer starts at the beginning of the file
w+ Open a file for read/write. Erases the contents of the file or creates a new file
if it doesn't exist. File pointer starts at the beginning of the file
a+ Open a file for read/write. The existing data in file is preserved. File pointer
starts at the end of the file. Creates a new file if the file doesn't exist
x+ Creates a new file for read/write. Returns FALSE and an error if file already
exists
fopen()
FILE OPERATIONS
• The fread() function reads from an open file.
• The fclose() function is used to close an open file.
• The fgets() function is used to read a single line from a file.
• The feof() function checks if the "end-of-file" (EOF) has been
reached.
• The fgetc() function is used to read a single character from a file.
• The fwrite() function is used to write to a file.
COOKIES
• A cookie is a small file with the maximum size of 4KB that the
web server stores on the client computer.
• They are typically used to keeping track of information such as a
username that the site can retrieve to personalize the page when
the user visits the website next time.
• A cookie can only be read from the domain that it has been issued
from.
Create Cookies With PHP
• A cookie is created with the setcookie() function.
• The value of the cookie can be retrieved using the global variable
$_COOKIE.
• isset() function is used to find out if the cookie is set.
• The setcookie() function must appear before the <html> tag.
• To delete a cookie, use the setcookie() function with an
expiration date in the past.
• Check whether cookies enabled or not!!!!
DATABASE CONNECTIVITY
• In PHP, we can connect to the database using XAMPP web server
by using "localhost/phpmyadmin".
• Open XAMPP and start running Apache, MySQL
DATABASE CONNECTIVITY
• Now open PHP file and write PHP code to create database and a
table in your database.
• Save the file as “data.php” in htdocs folder under XAMPP folder.
• Then open web browser and type localhost/data.php. Finally the
database is created and connected to PHP.
An introduction to PHP : PHP and Using PHP, Variables Program control and Built-in functions.pptx
An introduction to PHP : PHP and Using PHP, Variables Program control and Built-in functions.pptx
An introduction to PHP : PHP and Using PHP, Variables Program control and Built-in functions.pptx
An introduction to PHP : PHP and Using PHP, Variables Program control and Built-in functions.pptx
XML
• Xml (eXtensible Markup Language) is a mark up language.
• XML is designed to store and transport data.
• XML is not a replacement for HTML.
• XML is designed to be self-descriptive.
• XML is designed to carry data, not to display data.
• XML tags are not predefined. You must define your own tags.
• XML is platform independent and language independent.
XML FEATURES
• XML is widely used in the era of web development. It is also used
to simplify data storage and data sharing.
• The main features or advantages of XML are given below.
– XML separates data from HTML
– XML simplifies data sharing
– XML simplifies data transport
– XML simplifies Platform change
– XML increases data availability
– XML can be used to create new internet languages
DIFFERENCES BETWEEN XML AND HTML
• .
EXAMPLE
DTD
• DTD stands for Document Type Definition.
• It defines the legal building blocks of an XML document.
• It is used to define document structure with a list of legal elements
and attributes.
• Its main purpose is to define the structure of an XML document.
• It contains a list of legal elements and define the structure with the
help of them.
• Before proceeding with XML DTD, you must check the
validation. An XML document is called "well-formed" if it
contains the correct syntax.
AN INTERNAL DTD DECLARATION
• If the DTD is declared inside the XML file, it must be wrapped
inside the <!DOCTYPE> definition:
AN EXTERNAL DTD DECLARATION
• If the DTD is declared in an external file, the <!DOCTYPE>
definition must contain a reference to the DTD file:
DTD - XML BUILDING BLOCKS
• All XML documents are made up by the following building
blocks:
– Elements : main building blocks of both XML and HTML
documents
– Attributes : provide extra information about elements
– Entities : expanded when a document is parsed by an XML
parser
– PCDATA : parsed character data
– CDATA : character data
XML PARSERS
• An XML parser is a software library or package that provides
interfaces for client applications to work with an XML document.
• The XML Parser is designed to read the XML and create a way for
programs to use XML.
• XML parser validates the document and check that the document
is well formatted.
XML DOM
• DOM is an acronym stands for Document Object Model.
• It defines a standard way to access and manipulate documents.
• Document Object Model (DOM) is a programming API for HTML
and XML documents.
• It defines the logical structure of documents and the way a
document is accessed and manipulated.
• XML DOM defines a standard way to access and manipulate XML
documents.
XML DOM
XML DOM
Ad

Recommended

PHP language presentation
PHP language presentation
Annujj Agrawaal
 
PHP Hypertext Preprocessor
PHP Hypertext Preprocessor
adeel990
 
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
DRambabu3
 
Php
Php
TSUBHASHRI
 
Php
Php
TSUBHASHRI
 
Php
Php
TSUBHASHRI
 
PHP
PHP
sometech
 
Php basics
Php basics
sagaroceanic11
 
PHP - Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
Php Tutorial
Php Tutorial
SHARANBAJWA
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATION
krutitrivedi
 
PHP Comprehensive Overview
PHP Comprehensive Overview
Mohamed Loey
 
php Chapter 1.pptx
php Chapter 1.pptx
HambaAbebe2
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdf
HambardeAtharva
 
Php mysql
Php mysql
Ajit Yadav
 
Day1
Day1
IRWAA LLC
 
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
 
10_introduction_php.ppt
10_introduction_php.ppt
MercyL2
 
introduction_php.ppt
introduction_php.ppt
ArunKumar313658
 
Introduction to PHP.pptx
Introduction to PHP.pptx
SherinRappai
 
PHP and MySQL.ppt
PHP and MySQL.ppt
ROGELIOVILLARUBIA
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
introduction to php and its uses in daily
introduction to php and its uses in daily
vishal choudhary
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)
Guni Sonow
 
Php mysql
Php mysql
Alebachew Zewdu
 
Php
Php
khushbulakhani1
 
Php
Php
samirlakhanistb
 
Importing Matplotlib - Line plots - Scatter plots Visualizing errors.pptx
Importing Matplotlib - Line plots - Scatter plots Visualizing errors.pptx
Vigneshkumar Ponnusamy
 
Cloud Service Management Capex vs Opex Shift.pptx
Cloud Service Management Capex vs Opex Shift.pptx
Vigneshkumar Ponnusamy
 

More Related Content

Similar to An introduction to PHP : PHP and Using PHP, Variables Program control and Built-in functions.pptx (20)

PHP - Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
Php Tutorial
Php Tutorial
SHARANBAJWA
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATION
krutitrivedi
 
PHP Comprehensive Overview
PHP Comprehensive Overview
Mohamed Loey
 
php Chapter 1.pptx
php Chapter 1.pptx
HambaAbebe2
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdf
HambardeAtharva
 
Php mysql
Php mysql
Ajit Yadav
 
Day1
Day1
IRWAA LLC
 
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
 
10_introduction_php.ppt
10_introduction_php.ppt
MercyL2
 
introduction_php.ppt
introduction_php.ppt
ArunKumar313658
 
Introduction to PHP.pptx
Introduction to PHP.pptx
SherinRappai
 
PHP and MySQL.ppt
PHP and MySQL.ppt
ROGELIOVILLARUBIA
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
introduction to php and its uses in daily
introduction to php and its uses in daily
vishal choudhary
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)
Guni Sonow
 
Php mysql
Php mysql
Alebachew Zewdu
 
Php
Php
khushbulakhani1
 
Php
Php
samirlakhanistb
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATION
krutitrivedi
 
PHP Comprehensive Overview
PHP Comprehensive Overview
Mohamed Loey
 
php Chapter 1.pptx
php Chapter 1.pptx
HambaAbebe2
 
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
 
10_introduction_php.ppt
10_introduction_php.ppt
MercyL2
 
Introduction to PHP.pptx
Introduction to PHP.pptx
SherinRappai
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
introduction to php and its uses in daily
introduction to php and its uses in daily
vishal choudhary
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)
Guni Sonow
 

More from Vigneshkumar Ponnusamy (7)

Importing Matplotlib - Line plots - Scatter plots Visualizing errors.pptx
Importing Matplotlib - Line plots - Scatter plots Visualizing errors.pptx
Vigneshkumar Ponnusamy
 
Cloud Service Management Capex vs Opex Shift.pptx
Cloud Service Management Capex vs Opex Shift.pptx
Vigneshkumar Ponnusamy
 
Web Technologies Introduction to web technologies
Web Technologies Introduction to web technologies
Vigneshkumar Ponnusamy
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptx
Vigneshkumar Ponnusamy
 
CS8651 IP Unit 3.pptx
CS8651 IP Unit 3.pptx
Vigneshkumar Ponnusamy
 
IP Unit 2.pptx
IP Unit 2.pptx
Vigneshkumar Ponnusamy
 
CS8651 Internet Programming - Basics of HTML, HTML5, CSS
CS8651 Internet Programming - Basics of HTML, HTML5, CSS
Vigneshkumar Ponnusamy
 
Importing Matplotlib - Line plots - Scatter plots Visualizing errors.pptx
Importing Matplotlib - Line plots - Scatter plots Visualizing errors.pptx
Vigneshkumar Ponnusamy
 
Cloud Service Management Capex vs Opex Shift.pptx
Cloud Service Management Capex vs Opex Shift.pptx
Vigneshkumar Ponnusamy
 
Web Technologies Introduction to web technologies
Web Technologies Introduction to web technologies
Vigneshkumar Ponnusamy
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptx
Vigneshkumar Ponnusamy
 
CS8651 Internet Programming - Basics of HTML, HTML5, CSS
CS8651 Internet Programming - Basics of HTML, HTML5, CSS
Vigneshkumar Ponnusamy
 
Ad

Recently uploaded (20)

Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Wax Moon, Richmond, VA. Terrence McPherson
Wax Moon, Richmond, VA. Terrence McPherson
TerrenceMcPherson1
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
GlysdiEelesor1
 
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
TechSoup
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
Measuring, learning and applying multiplication facts.
Measuring, learning and applying multiplication facts.
cgilmore6
 
Plate Tectonic Boundaries and Continental Drift Theory
Plate Tectonic Boundaries and Continental Drift Theory
Marie
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Wax Moon, Richmond, VA. Terrence McPherson
Wax Moon, Richmond, VA. Terrence McPherson
TerrenceMcPherson1
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
GlysdiEelesor1
 
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
TechSoup
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
Measuring, learning and applying multiplication facts.
Measuring, learning and applying multiplication facts.
cgilmore6
 
Plate Tectonic Boundaries and Continental Drift Theory
Plate Tectonic Boundaries and Continental Drift Theory
Marie
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
Ad

An introduction to PHP : PHP and Using PHP, Variables Program control and Built-in functions.pptx

  • 1. UNIT 4- PHP & XML CS8651 - INTERNET PROGRAMMING
  • 2. • An introduction to PHP: PHP- Using PHP- Variables- Program control- Built-in functions- Form Validation- Regular Expressions - File handling – Cookies - Connecting to Database. • XML: Basic XML- Document Type Definition- XML Schema DOM and Presenting XML, XML • Parsers and Validation, XSL and XSLT Transformation, News Feed (RSS and ATOM). UNIT IV: SYLLABUS
  • 4. • PHP is an open-source, interpreted, and object-oriented scripting language that can be executed at the server-side. • PHP is well suited for web development. • PHP stands for Hypertext Pre-processor. • PHP is an interpreted language, i.e., there is no need for compilation. • PHP is faster than other scripting languages, for example, ASP and JSP. PHP
  • 5. • PHP is a server-side scripting language, which is used to manage the dynamic content of the website. • PHP can be embedded into HTML. • PHP is an object-oriented language. • PHP is an open-source scripting language. • PHP is simple and easy to learn language. PHP
  • 6. • PHP is a server-side scripting language, which is used to design the dynamic web applications with MySQL database. – It handles dynamic content, database as well as session tracking for the website. – You can create sessions in PHP. – It can access cookies variable and also set cookies. – It helps to encrypt the data and apply validation. – PHP supports several protocols such as HTTP, POP3, SNMP, LDAP, IMAP, and many more. WHY USE PHP?
  • 7. – Using PHP language, you can control the user to access some pages of your website. – As PHP is easy to install and set up, this is the main reason why PHP is the best language to learn. – PHP can handle the forms, such as - collect the data from users using forms, save it into the database, and return useful information to the user. For example - Registration form. WHY USE PHP?
  • 9. • How to install XAMPP server on windows - https://www.apachefriends.org/download.html INSTALL PHP
  • 10. • After downloading XAMPP, double click on the downloaded file and allow XAMPP to make changes in your system. A window will pop-up, where you have to click on the Next button. INSTALL PHP
  • 11. • XAMPP is ready to use. Start the Apache server and MySQL and run the php program on the localhost. INSTALL PHP
  • 12. • If no error is shown, then XAMPP is running successfully. INSTALL PHP
  • 13. • PHP programs can be written on any editor, such as - Notepad, Notepad++, Dreamweaver, etc. • These programs save with .php extension, i.e., filename.php inside the htdocs folder. • Step 1: Create a simple PHP program like hello world. <!DOCTYPE html> <html> <body> <h1>PHP</h1> <?php echo "Hello World"; ?> </body></html> RUN PHP CODE IN XAMPP
  • 14. • Step 2: Save the file with hello.php name in the htdocs folder, which resides inside the xampp folder. • Step 3: Run the XAMPP server and start the Apache and MySQL. • Step 4: Now, open the web browser and type localhost – http://localhost/hello.php on your browser window. RUN PHP CODE IN XAMPP
  • 15. • In PHP, keyword (e.g., echo, if, else, while), functions, user- defined functions, classes are not case-sensitive. • However, all variable names are case-sensitive. PHP - CASE SENSITIVE
  • 16. • A variable is a name given to a memory location that stores data at runtime. • The scope of a variable determines its visibility. • The rules followed when creating variables in PHP – All variable names must start with the dollar sign. – Variable names are case sensitive; – All variables names must start with a letter follow other characters – Variable names must not contain any spaces PHP - VARIABLE
  • 21. • A function is a block of statements that can be used repeatedly in a program. • A function is a self-contained block of code that performs a specific task. • A function is a piece of code which takes one or more input in the form of parameter and does some processing and returns a value. PHP FUNCTIONS
  • 22. • Better code organization – PHP functions allow us to group blocks of related code that perform a specific task together. • Reusability – Once defined, a function can be called by a number of scripts in our PHP files. This saves us time of reinventing the wheel when we want to perform some routine tasks such as connecting to the database • Easy maintenance – Updates to the system only need to be made in one place. WHY USE PHP FUNCTIONS?
  • 23. • An HTML form contains various input fields such as text box, checkbox, radio buttons, submit button, and checklist, etc. • These input fields need to be validated, which ensures that the user has entered information in all the required fields and also validates that the information provided by the user is valid and correct. • There are two types of validation are available in PHP. • Client-Side Validation − Validation is performed on the client machine web browsers. • Server Side Validation − After submitted by data, the data has sent to a server and perform validation checks in server machine. FORM VALIDATION
  • 24. • The things need to be validate are as follows: – Empty String – Validate String – Validate Numbers – Validate Email – Validate URL – Input length FORM VALIDATION
  • 25. • A regular expression is a sequence of characters that forms a search pattern. • When you search for data in a text, you can use this search pattern to describe what you are searching for. • A regular expression can be a single character, or a more complicated pattern. • Regular expressions can be used to perform all types of text search and text replace operations. REGULAR EXPRESSION
  • 26. • In PHP, regular expressions are strings composed of delimiters, a pattern and optional modifiers. • In the example above, / is the delimiter, w3schools is the pattern that is being searched for, and i is a modifier that makes the search case-insensitive. REGULAR EXPRESSION - SYNTAX
  • 27. • Modifiers can change how a search is performed. REGULAR EXPRESSION - MODIFIERS
  • 28. • PHP supports file handling which is used to read, write and append data to the file. • Basic file handling steps – Opening a file fopen() – Reading a file fclose() – Writing a file fread() – Closing a file fwrite() – Delete File unlink() FILE HANDLING
  • 29. • PHP fopen() function is used to open file or URL and returns resource. • The fopen() function accepts two arguments: $filename and $mode. • The $filename represents the file to be opended and $mode represents the file mode for example read-only, read-write, write- only etc. fopen()
  • 30. Modes Description r Open a file for read only. File pointer starts at the beginning of the file w Open a file for write only. Erases the contents of the file or creates a new file if it doesn't exist. File pointer starts at the beginning of the file a Open a file for write only. The existing data in file is preserved. File pointer starts at the end of the file. Creates a new file if the file doesn't exist x Creates a new file for write only. Returns FALSE and an error if file already exists r+ Open a file for read/write. File pointer starts at the beginning of the file w+ Open a file for read/write. Erases the contents of the file or creates a new file if it doesn't exist. File pointer starts at the beginning of the file a+ Open a file for read/write. The existing data in file is preserved. File pointer starts at the end of the file. Creates a new file if the file doesn't exist x+ Creates a new file for read/write. Returns FALSE and an error if file already exists fopen()
  • 31. FILE OPERATIONS • The fread() function reads from an open file. • The fclose() function is used to close an open file. • The fgets() function is used to read a single line from a file. • The feof() function checks if the "end-of-file" (EOF) has been reached. • The fgetc() function is used to read a single character from a file. • The fwrite() function is used to write to a file.
  • 32. COOKIES • A cookie is a small file with the maximum size of 4KB that the web server stores on the client computer. • They are typically used to keeping track of information such as a username that the site can retrieve to personalize the page when the user visits the website next time. • A cookie can only be read from the domain that it has been issued from.
  • 33. Create Cookies With PHP • A cookie is created with the setcookie() function. • The value of the cookie can be retrieved using the global variable $_COOKIE. • isset() function is used to find out if the cookie is set. • The setcookie() function must appear before the <html> tag. • To delete a cookie, use the setcookie() function with an expiration date in the past. • Check whether cookies enabled or not!!!!
  • 34. DATABASE CONNECTIVITY • In PHP, we can connect to the database using XAMPP web server by using "localhost/phpmyadmin". • Open XAMPP and start running Apache, MySQL
  • 35. DATABASE CONNECTIVITY • Now open PHP file and write PHP code to create database and a table in your database. • Save the file as “data.php” in htdocs folder under XAMPP folder. • Then open web browser and type localhost/data.php. Finally the database is created and connected to PHP.
  • 40. XML • Xml (eXtensible Markup Language) is a mark up language. • XML is designed to store and transport data. • XML is not a replacement for HTML. • XML is designed to be self-descriptive. • XML is designed to carry data, not to display data. • XML tags are not predefined. You must define your own tags. • XML is platform independent and language independent.
  • 41. XML FEATURES • XML is widely used in the era of web development. It is also used to simplify data storage and data sharing. • The main features or advantages of XML are given below. – XML separates data from HTML – XML simplifies data sharing – XML simplifies data transport – XML simplifies Platform change – XML increases data availability – XML can be used to create new internet languages
  • 42. DIFFERENCES BETWEEN XML AND HTML • .
  • 44. DTD • DTD stands for Document Type Definition. • It defines the legal building blocks of an XML document. • It is used to define document structure with a list of legal elements and attributes. • Its main purpose is to define the structure of an XML document. • It contains a list of legal elements and define the structure with the help of them. • Before proceeding with XML DTD, you must check the validation. An XML document is called "well-formed" if it contains the correct syntax.
  • 45. AN INTERNAL DTD DECLARATION • If the DTD is declared inside the XML file, it must be wrapped inside the <!DOCTYPE> definition:
  • 46. AN EXTERNAL DTD DECLARATION • If the DTD is declared in an external file, the <!DOCTYPE> definition must contain a reference to the DTD file:
  • 47. DTD - XML BUILDING BLOCKS • All XML documents are made up by the following building blocks: – Elements : main building blocks of both XML and HTML documents – Attributes : provide extra information about elements – Entities : expanded when a document is parsed by an XML parser – PCDATA : parsed character data – CDATA : character data
  • 48. XML PARSERS • An XML parser is a software library or package that provides interfaces for client applications to work with an XML document. • The XML Parser is designed to read the XML and create a way for programs to use XML. • XML parser validates the document and check that the document is well formatted.
  • 49. XML DOM • DOM is an acronym stands for Document Object Model. • It defines a standard way to access and manipulate documents. • Document Object Model (DOM) is a programming API for HTML and XML documents. • It defines the logical structure of documents and the way a document is accessed and manipulated. • XML DOM defines a standard way to access and manipulate XML documents.