1 Introduction to PHP 2 What Is PHP Stands for Personal Home Page orPHP Hypertext
Advantages of Using PHP to enhance Web pages
Easy to use.
Open source.
Multiple platform.
3 How PHP Pages are Accessed and Interpreted 4 Getting Started with PHP
To develop and publish PHP scripts all you need is
A Web server with PHP built into it
A client machine with a basic text editor and Internet connectionTextPad
FTP or Telnet softwareat Conestoga we are saving the files under C\Inetpub\wwwroot\name.p hp
5 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 using .php extension.
2. Use copy to copy the file to the server.
3. Access your file using a browser.
6 Creating a PHP Script File and Saving It to a Local Disk
You can use a number of different editors to create your PHP script files.
The PHP script starts with a ltphp tag and ends with gt.
Between these tags is a singlePHP print statement.
7 Alternative PHP Delimiters
You can alternatively start your PHP scripts with the ltscriptgt tag as follows
ltscript languagePHPgt
print (A simple initial script)
lt/scriptgt
If have short_open_tag enabled in its configuration file you can use lt and gt.
If asp_tags is enabled in the PHP configuration file you can use lt and gt as delimiters.
8 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
9 If Use Improper Syntax
Suppose you use the wrong syntax
ltphp print ( A simple initial script)
gt
10 Php not giving errors
If php is not giving errors
Open the php.ini file under c\php5 in textpad approx line 357
Change the
Display_errorson
11 PHPs 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.
12 Embedding PHP Statements Within HTML Documents save as programName.php to run http//localhost/programName.php
One way to use PHP is to embed PHP scripts within HTML tags in an HTML document.
lthtmlgt
ltheadgt
lttitlegtHTML With PHP Embeddedlt/titlegt lt/headgt
ltbodygt
ltfont size5 colorbluegtWelcome To My Pagelt/fontgt
ltscript text phpgt
print (Using PHP is not hard)
lt/scriptgt
this is instead of Hello World
lt/bodygtlt/htmlgt
13 Would Output The Following ... 14 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 beoutputprint (ltfont color\blue\gt)
The above statement would output
ltfont colorbluegt
15 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.
16 Using Comments with PHP Scripts
Comment Syntax - Use //
ltphp
// This is a comment
gt
Can place on Same line as a statement
ltphp
print (A simple initial script) //Output a line
gt
17 Example Script with Comments
lthtmlgt ltheadgt
lttitlegt Generating HTML From PHPlt/titlegt lt/headgt
ltbodygt lth1gt Generating HTML From PHPlt/h1gt
ltphp
//
// Example script to output HTML tags
//
print (Using PHP has ltigtsome advantageslt/igt)
print (ltulgtltligtSpeedlt/ligtltligtEase of uselt/ligt
ltligtFunctionalitylt/ligtlt/ulgt) //Output bullet list
print (lt/bodygtlt/htmlgt)
gt
18 Alternative Comment Syntax
PHP allows a couple of additional ways to create comments.
ltphp
phpinfo() This is a built-in function
gt
Multiple line comments. ltphp
/
A script that gets information about the
PHP version being used.
/
lt phpinfo() gt
19 Using PHP Variables
Variables are used to store and access data in computer memory.
A variable name is a label used within a script to refer to the data.
20 Assigning New Values to Variables
You can assign new values to variables
days 3
newdays 100
days newdays
At the end of these three lines days and newdays both have values of 100.
21 Selecting Variable Names
You can select just about any set of characters for a variable name in PHP but they must
Use a dollar sign () as the first character
Use a letter or an underscore character (_) as the second character.
NoteTry to select variable names that help describe their function. For example counter is more descriptive than c or ctr.
Must follow Conestoga Standards camelNotation
22 Combining Variables and the print Statement
That is to print out the value of x write the following PHP statement
print (x)
The following code will output Bryant is 6 years old.
age6
print (Bryant is age years old.)
23 A Full Example ...
lthtmlgt
ltheadgt lttitlegtVariable Example lt/titlegt lt/headgt
ltbodygt
ltphp
firstNum 12
secondNum 356
temp firstNum
firstNum secondNnum
secondNum temp
print (First Number firstNum ltbrgtSecond Number secondNum)
gt lt/bodygt lt/htmlgt
24 Gives you ... 25 Using Arithmetic Operators
You can use operators such as a plus sign () for addition and a minus sign () for subtraction to build mathematical expressions.
For example
ltphp
apples 12
oranges 14
totalFruit apples oranges
print (The total number of fruit is totalFruit)
gt
These PHP statements would output
The total number of fruit is 26.
26 Common PHP Numeric Operators 27 Example
lthtmlgt
ltheadgt lttitlegtVariable Example lt/titlegt lt/headgt
ltbodygt
ltphp
columns 20
rows 12
totalSeats rows columns
ticketCost 3.75
totalRevenue totalSeats ticketCost
building_cost 300
profit totalRevenue - buildingCost
print (Total Seats are totalSeats ltbrgt)
print (Total Revenue is totalRevenue ltbrgt)
print (Total Profit is profit)
gt
lt/bodygt lt/htmlgt
28 Gives you ... 29 WARNING Using Variables with Undefined Values If you accidentally use a variable that does not have a value assigned to it will have no value (called a null value). When a variable with a null value is used in an expression PHP PHP may not generate an error and may complete the expression evaluation. For example the following PHP script will output x y4. ltphp y 3 yy x 1 // x has a null value print (xx yy) gt 30 Example
lthtmlgt
ltheadgt lttitlegtExpression Example lt/titlegt lt/headgt
ltbodygt
ltphp
grade1 50
grade2 100
grade3 75
average (grade1 grade2 grade3) / 3
print (The average is average)
gt
lt/bodygt lt/htmlgt
31 Gives you ... 32 Working with PHP String Variables
Character strings are used in scripts to hold data such as customer names addresses product names and descriptions.
Consider the following example.
nameChristopher
preferenceMilk Shake
name is assigned Christopher and the variable preference is assigned Milk Shake.
33 WARNING Be Careful Not to Mix Variable Types
Be careful not to mix string and numeric variable types.
For example you might expect the following statements to generate an error message but they will not. Instead they will output y1.
ltphp
x banana
sum 1 x
print (ysum)
gt
34 Using the Concatenate Operator. Vs
The concatenate operator combines two separate string variables into one.
For example
fullname firstname . lastname
fullname will receive the string values of firstname and lastname connected together.
For example
firstname John
lastname Smith
fullname firstname . lastname
print (Fullnamefullname)
35 TIP An Easier Way to Concatenate Strings
You can also use double quotation marks to create
concatenation directly
For example
Fullname FirstName LastName
//This statement has the same effect as
Fullname FirstName . . LastName
36 The strlen() Function
Most string functions require you to send them one or more arguments.
Arguments are input values that functions use in the processing they do.
Often functions return a value to the script based on the input arguments. For example
37 The strlen() Function Example
ltphp
comments Good Job
len strlen(comments)
print (Lengthlen)
gt
This PHP script would output Length8. 38 The trim() Function
This function removes any blank characters from the beginning and end of a string. For example consider the following script
ltphp
inName Easter Bunny
name trim(inName)
print (namenamename)
gt
Would Print nameEaster BunnnyEaster Bunny
39 The strtolower() and strtoupper() Functions
These functions return the input string in all uppercase or all lowercase letters respectively.
For example
ltphp
inQuote Now Is The Time
lower strtolower(inQuote)
upper strtoupper(inQuote)
print (upperupper lowerlower)
gt
The above would output upperNOW IS THE TIME lowernow is the time.
40 The substr() Function
Substr has the following general format
41 The substr() Function
The substr() function enumerates character positions starting with 0 (not 1)
For example in the string Homer the H would be position 0 the o would be position 1 the m position 2 and so on.
For example the following would output
Month12 Day25.
ltphp
date 12/25/2009
month substr(date 0 2)
day substr(date 3 2)
print (Monthmonth Dayday)
gt
42 The substr() Function
As another example consider the following use of the substr() function
It does not include the third argument (and thus returns a substring from the starting position to the end of the search string).
ltphp
date 12/25/2099
year substr(date 6)
print (Yearyear)
gt
The above script segment would output Year2099.
43 Example with Buttons lthtmlgt ltheadgt lttitlegt A Simple Form lt/titlegt lt/headgt ltbodygt ltform actionnameOfThePHP.phpmeth odpost gt Click submit to start our initial PHP program. ltbrgt ltinput typesubmit valueClick To Submitgt ltinput typereset valueErase and Restartgt lt/formgt lt/bodygt lt/htmlgt 44 Gives you ... 45 Receiving Input into PHP
To receive HTML form input into a PHP script
Use a PHP var name that matches the variable defined in the form elements name argument.
For example if form uses the following
ltinput typeradio namecontact valueYesgt
Then form-handling PHP script could use a variable called contact.
If the user clicks the radio button then contact would Yes
46 To Receive Data from HTML
_POSTname gt.
Enclose in square bracket and then quotes Name of HTML form variable (note do not use ) Special PHP Global variable. Technically it is an associative array 47 Another Example.
Suppose your HTML form uses the following
Enter email address ltinput typetext size16 maxlength20 nameemailgt
48 Gives you ... 49 Create Using textpad or Dreamweaver this html Save in C\inetpub\wwwroot\exercise 50 Receiving File in the same location same name with .php as the extension
About PowerShow.com
PowerShow.com is a leading presentation/slideshow sharing website. Whether your application is business, how-to, education, medicine, school, church, sales, marketing, online training or just for fun, PowerShow.com is a great resource. And, best of all, most of its cool features are free and easy to use.
You can use PowerShow.com to find and download example online PowerPoint ppt presentations on just about any topic you can imagine so you can learn how to improve your own slides and presentations for free. Or use it to find and download high-quality how-to PowerPoint ppt presentations with illustrated or animated slides that will teach you how to do something new, also for free. Or use it to upload your own PowerPoint slides so you can share them with your teachers, class, students, bosses, employees, customers, potential investors or the world. Or use it to create really cool photo slideshows - with 2D and 3D transitions, animation, and your choice of music - that you can share with your Facebook friends or Google+ circles. That's all free as well!
For a small fee you can get the industry's best online privacy or publicly promote your presentations and slide shows with top rankings. But aside from that it's free. We'll even convert your presentations and slide shows into the universal Flash format with all their original multimedia glory, including animation, 2D and 3D transition effects, embedded music or other audio, or even video embedded in slides. All for free. Most of the presentations and slideshows on PowerShow.com are free to view, many are even free to download. (You can choose whether to allow people to download your original PowerPoint presentations and photo slideshows for a fee or free or not at all.) Check out PowerShow.com today - for FREE. There is truly something for everyone!