SlideShare a Scribd company logo
1 of 34
Download to read offline
9/4/2017 CS346 PHP 1
Module 1
Introduction to PHP
Ahmed Elshal
9/4/2017 CS346 PHP 2
PHP Tutorial
http://www.kfs.edu.eg/
https://twitter.com/Ahmed_Elshal2
https://www.facebook.com/profile.php?id=100009938688890
https://www.linkedin.com/in/ahmed-elshal-03338a124/
Software Engineer.Ahmed Morshedy Elshal
Student in Faculty of Computers and Information
PHP References
 General: Download, documentation
 http://www.php.net/
 Documentation: manual
 http://www.php.net/manual/en/
http://us2.php.net/manual/en/index.php
 PHP.net tutorial
 http://php.net/manual/en/tutorial.php
 W3schools tutorial
http://www.w3schools.com/php/default.asp
9/4/2017 CS346 PHP 3
PHP functions
 Documented PHP functions
 http://us2.php.net/quickref.php
 You can create your own functions too
9/4/2017 CS346 PHP 4
9/4/2017 CS346 PHP 5
Objectives
 What is PHP?
 How does a PHP script work with a
Web Browser and a Web Server?
 What software and components you
need to get started with PHP?
 To create and run a simple PHP script
9/4/2017 CS346 PHP 6
What Is PHP?
 PHP, PHP Hypertext Preprocessor
 Server-side scripting languages for creating
dynamic web pages
9/4/2017 CS346 PHP 7
PHP advantages
Advantages of Using PHP to enhance Web
pages:
 Easy to use
 Simpler than Perl
 Open source
 Multiple platform.
9/4/2017 CS346 PHP 8
How PHP Pages are Accessed
and Interpreted
Client: Web browser Web server
1.Form submitted with a submit button
2.----- Action sends a request to the php file in server
3. Receive the request, find the file,
and read it
4. Execute the PHP commands
5. Send the results back
6. ---- results returned as HTML file
7. Web browser renders the HTML file, displaying the results
9/4/2017 CS346 PHP 9
Getting Started with PHP
To develop and publish PHP scripts you need:
 A client machine with a basic text editor and
Internet connection
• Prepare a text file with .php extension
 FTP or Telnet software
• Upload the file.php to the server
 A Web server with PHP built into it
• Process the file.php
9/4/2017 CS346 PHP 10
WHH Note
 This means that a browser e.g. IE or
Firefox on the client computer will not
recognize or render a file with extension
.php
 How do you check your PHP script before
submission to server?
9/4/2017 CS346 PHP 11
Getting Started with PHP
Set up development computer as a server
 Laptop contains a server and a browser environment
 Laptop is also set up as a Web server - WAMPserver
• Windows Apache, MySQL, PHP
 Client machine: PC, XP, editors, browsers
 Internet connection not needed
 Use copy and paste to transfer the scripts
 For class demos:
 localhost or 127.0.0.1 or cs346 server
9/4/2017 CS346 PHP 12
Exploring the Basic PHP
Development Process
The basic steps you can use to develop and
publish PHP pages are:
1. Create a PHP script file and save it to a local disk
• Test on localhost until satisfied
2. Use FTP to copy the file to the server
3. Access your file via URL on server using a
browser
• IE, Netscape, Opera, etc.
9/4/2017 CS346 PHP 13
Check PHP installation
 Create a simple PHP script, called
phpinfo.php
 The PHP script starts with a <?php tag and
ends with ?>
 Between these tags is a single PHP
statement: phpinfo();
 Copy the file to a directory of local server
 For WAMP: wamp/www
 Access the file with a browser
 http://localhost/checkphp.php
9/4/2017 CS346 PHP 14
Checking the server set up
 Upload the phpinfo.php to cs346 server
 E.g. to huen/m00
 Click on the link
 http://cs346.cs.uwosh.edu/huen/m00/phpinfo.php
 Check the various environments:
 Apache
 MySQL
 PHP functions
 variables
9/4/2017 CS346 PHP 15
9/4/2017 CS346 PHP 16
9/4/2017 CS346 PHP 17
Creating a PHP Script File
 Create PHP script welcome.php
 Starts with a <?php tag and ends with ?>
 Between these tags is a single PHP print
statement
 Copy the file to C:wampwww
 Access the file with
http://127.0.0.1/welcome.php
 Demo on localhost
 Demo on cs346 server
Similarly for other PHP scripts
 Upload welcome.php to huen/m00
 Click on
 http://cs346.cs.uwosh.edu/huen/m00/welcome.php
9/4/2017 CS346 PHP 18
<?PHP
/* welcome.php */
print ("<h1 style="color: blue;">Welcome to PHP, CS346 class!</h1>");
/* Note the combination of html tags and css */
?>
9/4/2017 CS346 PHP 19
Note the effect of CSS
9/4/2017 CS346 PHP 20
Alternative PHP Delimiters
 You can alternatively start your PHP scripts
with the <script> tag as follows:
<script language="PHP">
print ("A simple initial script");
</script>
 If short_open_tag enabled in its configuration
file (php.ini), you can use <? and ?>.
 If asp_tags is enabled in the PHP
configuration file, you can use <% and %>
as delimiters.
9/4/2017 CS346 PHP 21
Proper Syntax
 If you have a syntax error then you have
written one or more PHP statements that are
grammatically incorrect in the PHP language.
 The print statement syntax:
print ( "Your message to print" );
Enclose message
in quotation
marks
Message to Output
End in a
semi-colon
Parenthesis are
optional
9/4/2017 CS346 PHP 22
If syntax is wrong
<?php
print ( "Welcome to PHP, CS346 class!);
?>
9/4/2017 CS346 PHP 23
A Little About PHP's Syntax
 Some PHP Syntax Issues:
 Be careful to use quotation marks, parentheses, and
brackets in pairs.
 Most PHP commands end with a semicolon (;).
 Be careful of case.
 PHP ignores blank spaces.
9/4/2017 CS346 PHP 24
Embedding PHP Statements Within
HTML Documents
 One way to use PHP is to embed PHP scripts
within HTML tags in an HTML document.
 Save the file first with extension html
 Validate the html file
 Change the extension to php
 Access the script by URL on server
9/4/2017 CS346 PHP 25
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>HTML With PHP Embedded </title>
</head>
<body>
<p style = "font-family:sans-serif; font-size:36;
color:yellow; background-color:green">
Welcome To My Page!
<?PHP
print ("<br /> Using PHP is not hard!");
?>
<br /> and you can learn it quickly!</p>
</body>
</html>
9/4/2017 CS346 PHP 26
When embedded1.php is accessed
9/4/2017 CS346 PHP 27
Using Backslash () to Generate
HTML Tags with print()
 Sometimes you want to output an HTML tag
that also requires double quotation marks.
 Use the backslash (“”) character to signal that the
double quotation marks themselves should be
output:
print ("<font color="blue">");
 The above statement would output:
<font color="blue">
9/4/2017 CS346 PHP 28
Using Comments with
PHP Scripts
 Comments enable you to include
descriptive text along with the PHP
script.
 Comment lines are ignored when the script
runs; they do not slow down the run-time.
 Comments have two common uses.
• Describe the overall script purpose.
• Describe particularly tricky script lines.
9/4/2017 CS346 PHP 29
Using Comments with PHP Scripts
Comment Syntax - Use //
standalone
<?php
// This is a comment
?>
Can be placed on Same line as a
statement:
<?php
print ("A simple initial script");
//Output a line
?>
9/4/2017 CS346 PHP 30
Example Script with Comments
1. <html> <head>
2. <title> Generating HTML From PHP</title> </head>
3. <body> <h1> Generating HTML From PHP</h1>
4. <?php
5. //
6. // Example script to output HTML tags
7. //
8. print ("Using PHP has <i>some advantages:</i>");
9. print ("<ul><li>Speed</li><li>Ease of use</li>
<li>Functionality</li></ul>"); //Output bullet list
10. print ("</body></html>");
11. ?>
9/4/2017 CS346 PHP 31
Alternative Comment Syntax
PHP allows a couple of additional ways to
create comments.
<?php
phpinfo(); # This is a built-in function
?>
Multiple line comments.
<?php
/*
A script that gets information about the
PHP version being used.
*/
<? phpinfo(); ?>
9/4/2017 CS346 PHP 32
Summary
 HTML pages are static and cannot interact with
users
 PHP is a free, open source technology that
enables documents to generate dynamic content
 PHP script has the extension of .php
 PHP script may be standalone or
 Can be embedded in an HTML document
9/4/2017 CS346 PHP 33
Summary
 Resources needed for development:
 Web server with built-in PHP
 a client machine with a basic text editor,
browser, and internet connections
 FTP or Telnet software to send the script to
the server
9/4/2017 CS346 PHP 34
Summary
 PHP script process:
 write the PHP script file
 copy the script file to the Web server
 access the file with a Web browser
 Comments can be proceeded with
 two forward slashes (//)
 or #
 or enclosed in /* and */

More Related Content

What's hot

SQL 2012 and Powershell for the Bleeding Edge DBA
SQL 2012 and Powershell for the Bleeding Edge DBASQL 2012 and Powershell for the Bleeding Edge DBA
SQL 2012 and Powershell for the Bleeding Edge DBAdpcobb
 
A Complete Installation Guide for Orangescrum
A Complete Installation Guide for OrangescrumA Complete Installation Guide for Orangescrum
A Complete Installation Guide for OrangescrumOrangescrum
 
Joomla 15 Quickstart
Joomla 15 QuickstartJoomla 15 Quickstart
Joomla 15 QuickstartAmyStephen
 
Webinar: PHP and MySQL - Server-side Scripting Language for Web Development
Webinar: PHP and MySQL - Server-side Scripting Language for Web Development  Webinar: PHP and MySQL - Server-side Scripting Language for Web Development
Webinar: PHP and MySQL - Server-side Scripting Language for Web Development Edureka!
 
Microsoft WebsiteSpark & Windows Platform Installer
Microsoft WebsiteSpark & Windows Platform InstallerMicrosoft WebsiteSpark & Windows Platform Installer
Microsoft WebsiteSpark & Windows Platform InstallerGeorge Kanellopoulos
 
How to Get started with Press2Flash in 8 Steps
How to Get started with Press2Flash in 8 StepsHow to Get started with Press2Flash in 8 Steps
How to Get started with Press2Flash in 8 StepsErwan Jegouzo
 
OWA And SharePoint Integration
OWA And SharePoint IntegrationOWA And SharePoint Integration
OWA And SharePoint Integrationjems7
 
My sql università di enna a.a. 2005-06
My sql   università di enna a.a. 2005-06My sql   università di enna a.a. 2005-06
My sql università di enna a.a. 2005-06YUCHENG HU
 
Web browser extensions development
Web browser extensions developmentWeb browser extensions development
Web browser extensions developmentdragoslargu
 
Raisa anthony web programming 1st week
Raisa anthony   web programming 1st weekRaisa anthony   web programming 1st week
Raisa anthony web programming 1st weekRaisa Anjani
 
Install WordPress Blogging Software with EasyPHP
Install WordPress Blogging Software with EasyPHPInstall WordPress Blogging Software with EasyPHP
Install WordPress Blogging Software with EasyPHPRupesh Kumar
 

What's hot (17)

Asp introduction
Asp introductionAsp introduction
Asp introduction
 
SQL 2012 and Powershell for the Bleeding Edge DBA
SQL 2012 and Powershell for the Bleeding Edge DBASQL 2012 and Powershell for the Bleeding Edge DBA
SQL 2012 and Powershell for the Bleeding Edge DBA
 
Installing apache and php
Installing apache and phpInstalling apache and php
Installing apache and php
 
Install
InstallInstall
Install
 
A Complete Installation Guide for Orangescrum
A Complete Installation Guide for OrangescrumA Complete Installation Guide for Orangescrum
A Complete Installation Guide for Orangescrum
 
Asp.net w3schools
Asp.net w3schoolsAsp.net w3schools
Asp.net w3schools
 
Joomla 15 Quickstart
Joomla 15 QuickstartJoomla 15 Quickstart
Joomla 15 Quickstart
 
Webinar: PHP and MySQL - Server-side Scripting Language for Web Development
Webinar: PHP and MySQL - Server-side Scripting Language for Web Development  Webinar: PHP and MySQL - Server-side Scripting Language for Web Development
Webinar: PHP and MySQL - Server-side Scripting Language for Web Development
 
Microsoft WebsiteSpark & Windows Platform Installer
Microsoft WebsiteSpark & Windows Platform InstallerMicrosoft WebsiteSpark & Windows Platform Installer
Microsoft WebsiteSpark & Windows Platform Installer
 
How to Get started with Press2Flash in 8 Steps
How to Get started with Press2Flash in 8 StepsHow to Get started with Press2Flash in 8 Steps
How to Get started with Press2Flash in 8 Steps
 
OWA And SharePoint Integration
OWA And SharePoint IntegrationOWA And SharePoint Integration
OWA And SharePoint Integration
 
My sql università di enna a.a. 2005-06
My sql   università di enna a.a. 2005-06My sql   università di enna a.a. 2005-06
My sql università di enna a.a. 2005-06
 
Web browser extensions development
Web browser extensions developmentWeb browser extensions development
Web browser extensions development
 
phpTutorial1
phpTutorial1phpTutorial1
phpTutorial1
 
Raisa anthony web programming 1st week
Raisa anthony   web programming 1st weekRaisa anthony   web programming 1st week
Raisa anthony web programming 1st week
 
Install WordPress Blogging Software with EasyPHP
Install WordPress Blogging Software with EasyPHPInstall WordPress Blogging Software with EasyPHP
Install WordPress Blogging Software with EasyPHP
 
Opr089 xx
Opr089 xxOpr089 xx
Opr089 xx
 

Similar to Php introduction (20)

Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php
PhpPhp
Php
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php intro
Php introPhp intro
Php intro
 
PHP.docx
PHP.docxPHP.docx
PHP.docx
 
Chp 08 php (shared)
Chp 08   php  (shared) Chp 08   php  (shared)
Chp 08 php (shared)
 
PHP
PHPPHP
PHP
 
Php unit i
Php unit i Php unit i
Php unit i
 
Php unit i
Php unit iPhp unit i
Php unit i
 
PHP LICTURES ..........
PHP LICTURES ..........PHP LICTURES ..........
PHP LICTURES ..........
 
PHP ITCS 323
PHP ITCS 323PHP ITCS 323
PHP ITCS 323
 
1 Introduction to PHP Overview This lab walks y.docx
1  Introduction to PHP Overview This lab walks y.docx1  Introduction to PHP Overview This lab walks y.docx
1 Introduction to PHP Overview This lab walks y.docx
 
Php intro
Php introPhp intro
Php intro
 
Php intro
Php introPhp intro
Php intro
 
Php intro
Php introPhp intro
Php intro
 
Php Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant KillerPhp Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant Killer
 
PHP
 PHP PHP
PHP
 
Php
PhpPhp
Php
 

More from Ahmed Elshal

Ahmed Elshal Resume
Ahmed Elshal Resume Ahmed Elshal Resume
Ahmed Elshal Resume Ahmed Elshal
 
Basic c# cheat sheet
Basic c# cheat sheetBasic c# cheat sheet
Basic c# cheat sheetAhmed Elshal
 
Software engineering tutorial
Software engineering tutorial Software engineering tutorial
Software engineering tutorial Ahmed Elshal
 
The Software Engineering Code and the ACM Code
The Software Engineering Code and the ACM CodeThe Software Engineering Code and the ACM Code
The Software Engineering Code and the ACM CodeAhmed Elshal
 

More from Ahmed Elshal (6)

Ahmed Elshal Resume
Ahmed Elshal Resume Ahmed Elshal Resume
Ahmed Elshal Resume
 
High school
High school High school
High school
 
Basic c# cheat sheet
Basic c# cheat sheetBasic c# cheat sheet
Basic c# cheat sheet
 
Smart targets
Smart targetsSmart targets
Smart targets
 
Software engineering tutorial
Software engineering tutorial Software engineering tutorial
Software engineering tutorial
 
The Software Engineering Code and the ACM Code
The Software Engineering Code and the ACM CodeThe Software Engineering Code and the ACM Code
The Software Engineering Code and the ACM Code
 

Recently uploaded

%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 

Recently uploaded (20)

%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 

Php introduction

  • 1. 9/4/2017 CS346 PHP 1 Module 1 Introduction to PHP Ahmed Elshal
  • 2. 9/4/2017 CS346 PHP 2 PHP Tutorial http://www.kfs.edu.eg/ https://twitter.com/Ahmed_Elshal2 https://www.facebook.com/profile.php?id=100009938688890 https://www.linkedin.com/in/ahmed-elshal-03338a124/ Software Engineer.Ahmed Morshedy Elshal Student in Faculty of Computers and Information
  • 3. PHP References  General: Download, documentation  http://www.php.net/  Documentation: manual  http://www.php.net/manual/en/ http://us2.php.net/manual/en/index.php  PHP.net tutorial  http://php.net/manual/en/tutorial.php  W3schools tutorial http://www.w3schools.com/php/default.asp 9/4/2017 CS346 PHP 3
  • 4. PHP functions  Documented PHP functions  http://us2.php.net/quickref.php  You can create your own functions too 9/4/2017 CS346 PHP 4
  • 5. 9/4/2017 CS346 PHP 5 Objectives  What is PHP?  How does a PHP script work with a Web Browser and a Web Server?  What software and components you need to get started with PHP?  To create and run a simple PHP script
  • 6. 9/4/2017 CS346 PHP 6 What Is PHP?  PHP, PHP Hypertext Preprocessor  Server-side scripting languages for creating dynamic web pages
  • 7. 9/4/2017 CS346 PHP 7 PHP advantages Advantages of Using PHP to enhance Web pages:  Easy to use  Simpler than Perl  Open source  Multiple platform.
  • 8. 9/4/2017 CS346 PHP 8 How PHP Pages are Accessed and Interpreted Client: Web browser Web server 1.Form submitted with a submit button 2.----- Action sends a request to the php file in server 3. Receive the request, find the file, and read it 4. Execute the PHP commands 5. Send the results back 6. ---- results returned as HTML file 7. Web browser renders the HTML file, displaying the results
  • 9. 9/4/2017 CS346 PHP 9 Getting Started with PHP To develop and publish PHP scripts you need:  A client machine with a basic text editor and Internet connection • Prepare a text file with .php extension  FTP or Telnet software • Upload the file.php to the server  A Web server with PHP built into it • Process the file.php
  • 10. 9/4/2017 CS346 PHP 10 WHH Note  This means that a browser e.g. IE or Firefox on the client computer will not recognize or render a file with extension .php  How do you check your PHP script before submission to server?
  • 11. 9/4/2017 CS346 PHP 11 Getting Started with PHP Set up development computer as a server  Laptop contains a server and a browser environment  Laptop is also set up as a Web server - WAMPserver • Windows Apache, MySQL, PHP  Client machine: PC, XP, editors, browsers  Internet connection not needed  Use copy and paste to transfer the scripts  For class demos:  localhost or 127.0.0.1 or cs346 server
  • 12. 9/4/2017 CS346 PHP 12 Exploring the Basic PHP Development Process The basic steps you can use to develop and publish PHP pages are: 1. Create a PHP script file and save it to a local disk • Test on localhost until satisfied 2. Use FTP to copy the file to the server 3. Access your file via URL on server using a browser • IE, Netscape, Opera, etc.
  • 13. 9/4/2017 CS346 PHP 13 Check PHP installation  Create a simple PHP script, called phpinfo.php  The PHP script starts with a <?php tag and ends with ?>  Between these tags is a single PHP statement: phpinfo();  Copy the file to a directory of local server  For WAMP: wamp/www  Access the file with a browser  http://localhost/checkphp.php
  • 15. Checking the server set up  Upload the phpinfo.php to cs346 server  E.g. to huen/m00  Click on the link  http://cs346.cs.uwosh.edu/huen/m00/phpinfo.php  Check the various environments:  Apache  MySQL  PHP functions  variables 9/4/2017 CS346 PHP 15
  • 17. 9/4/2017 CS346 PHP 17 Creating a PHP Script File  Create PHP script welcome.php  Starts with a <?php tag and ends with ?>  Between these tags is a single PHP print statement  Copy the file to C:wampwww  Access the file with http://127.0.0.1/welcome.php  Demo on localhost  Demo on cs346 server
  • 18. Similarly for other PHP scripts  Upload welcome.php to huen/m00  Click on  http://cs346.cs.uwosh.edu/huen/m00/welcome.php 9/4/2017 CS346 PHP 18 <?PHP /* welcome.php */ print ("<h1 style="color: blue;">Welcome to PHP, CS346 class!</h1>"); /* Note the combination of html tags and css */ ?>
  • 19. 9/4/2017 CS346 PHP 19 Note the effect of CSS
  • 20. 9/4/2017 CS346 PHP 20 Alternative PHP Delimiters  You can alternatively start your PHP scripts with the <script> tag as follows: <script language="PHP"> print ("A simple initial script"); </script>  If short_open_tag enabled in its configuration file (php.ini), you can use <? and ?>.  If asp_tags is enabled in the PHP configuration file, you can use <% and %> as delimiters.
  • 21. 9/4/2017 CS346 PHP 21 Proper Syntax  If you have a syntax error then you have written one or more PHP statements that are grammatically incorrect in the PHP language.  The print statement syntax: print ( "Your message to print" ); Enclose message in quotation marks Message to Output End in a semi-colon Parenthesis are optional
  • 22. 9/4/2017 CS346 PHP 22 If syntax is wrong <?php print ( "Welcome to PHP, CS346 class!); ?>
  • 23. 9/4/2017 CS346 PHP 23 A Little About PHP's Syntax  Some PHP Syntax Issues:  Be careful to use quotation marks, parentheses, and brackets in pairs.  Most PHP commands end with a semicolon (;).  Be careful of case.  PHP ignores blank spaces.
  • 24. 9/4/2017 CS346 PHP 24 Embedding PHP Statements Within HTML Documents  One way to use PHP is to embed PHP scripts within HTML tags in an HTML document.  Save the file first with extension html  Validate the html file  Change the extension to php  Access the script by URL on server
  • 25. 9/4/2017 CS346 PHP 25 <html xmlns = "http://www.w3.org/1999/xhtml"> <head> <title>HTML With PHP Embedded </title> </head> <body> <p style = "font-family:sans-serif; font-size:36; color:yellow; background-color:green"> Welcome To My Page! <?PHP print ("<br /> Using PHP is not hard!"); ?> <br /> and you can learn it quickly!</p> </body> </html>
  • 26. 9/4/2017 CS346 PHP 26 When embedded1.php is accessed
  • 27. 9/4/2017 CS346 PHP 27 Using Backslash () to Generate HTML Tags with print()  Sometimes you want to output an HTML tag that also requires double quotation marks.  Use the backslash (“”) character to signal that the double quotation marks themselves should be output: print ("<font color="blue">");  The above statement would output: <font color="blue">
  • 28. 9/4/2017 CS346 PHP 28 Using Comments with PHP Scripts  Comments enable you to include descriptive text along with the PHP script.  Comment lines are ignored when the script runs; they do not slow down the run-time.  Comments have two common uses. • Describe the overall script purpose. • Describe particularly tricky script lines.
  • 29. 9/4/2017 CS346 PHP 29 Using Comments with PHP Scripts Comment Syntax - Use // standalone <?php // This is a comment ?> Can be placed on Same line as a statement: <?php print ("A simple initial script"); //Output a line ?>
  • 30. 9/4/2017 CS346 PHP 30 Example Script with Comments 1. <html> <head> 2. <title> Generating HTML From PHP</title> </head> 3. <body> <h1> Generating HTML From PHP</h1> 4. <?php 5. // 6. // Example script to output HTML tags 7. // 8. print ("Using PHP has <i>some advantages:</i>"); 9. print ("<ul><li>Speed</li><li>Ease of use</li> <li>Functionality</li></ul>"); //Output bullet list 10. print ("</body></html>"); 11. ?>
  • 31. 9/4/2017 CS346 PHP 31 Alternative Comment Syntax PHP allows a couple of additional ways to create comments. <?php phpinfo(); # This is a built-in function ?> Multiple line comments. <?php /* A script that gets information about the PHP version being used. */ <? phpinfo(); ?>
  • 32. 9/4/2017 CS346 PHP 32 Summary  HTML pages are static and cannot interact with users  PHP is a free, open source technology that enables documents to generate dynamic content  PHP script has the extension of .php  PHP script may be standalone or  Can be embedded in an HTML document
  • 33. 9/4/2017 CS346 PHP 33 Summary  Resources needed for development:  Web server with built-in PHP  a client machine with a basic text editor, browser, and internet connections  FTP or Telnet software to send the script to the server
  • 34. 9/4/2017 CS346 PHP 34 Summary  PHP script process:  write the PHP script file  copy the script file to the Web server  access the file with a Web browser  Comments can be proceeded with  two forward slashes (//)  or #  or enclosed in /* and */