PHP First Steps - Overview
PHP and the WWW
PHP as a server-side language
What so great about PHP?
PHP in action
PHP basics
PHP and the Web
Apache, a program running on ... gets the message and asks the PHP interpreter,
another program running on the computer, “what does /index.php look like?”
PHP and the Web
The PHP interpreter reads the file /var/www/html/index.php from disk drive
The PHP interpreter runs the commands in index.php, possibly exchanging
data with a database program such as MySQL
The PHP interpreter takes the index.php program output and sends it back
to Apache as answer
PHP and the Web
Apache sends the page contents it got from the PHP interpreter back to your
computer over the Internet in response to Firefox
Firefox displays the page on the screen, following the instructions of the
HTML tags in the page
PHP – a server-side language
PHP runs on the web server
Javascript and Flash in contrast, are client-side because they run on a
web client
The instructions in a PHP program cause the PHP interpreter on a web server
to output a web page. The instructions in Javascript cause Firefox to run
browser commands.
So Great About PHP?
PHP is free
PHP is cross-platform
PHP is widely used
PHP hides its complexity
PHP is built for Web Programming
PHP in action
The PHP interpreter runs the commands between <?php ?> tags
PHP processing form data via $_POST
String syntax called a 'here document'
Using PHP internal library functions like number_format ()
Displaying infromation from a database
Basic Rules of PHP Programs
Start and End Tags
Whitespace and Case-Sensitivity
Comments
PHP usage by a web server to create a response to send back to browser
PHP basics, program structure, process form, and talk to databases
Working with Text and Numbers
Defining Text Strings
Validating and formatting text
Manipulating Text
Numbers
Arithmetic Operators
Variables
Putting variables inside strings
Text
Pieces of text are called strings
String can even contain binary file such as image or sound
String is surrounded by a single quotes.. single quotes are delimiters
Backslash to be used for escaping
The escape character can itself be escaped
Defining Text Strings
Variable names in a double-quoted string will be substituted with its value.This
is called as variable interpolation.
Here documents obey the same escape-character and variable substitution
rules
Use a . (period) to combine two strings.The . is the cancatenation.
Manipulating Text
Validating string using trim () and strlen ()
To compare two strings, use the equality operator (==)
Use strcasecmp () to compare strings ignoring case
Formatting Text
Use printf () with a format string and the items to print
Zero-padding, displaying signs with printf ()
Use of strtolower (), strtoupper (), ucwords (),ucfirst() substr (), str_replace
()
String Functions.
Any PHP script is built out of a series of statements.
A statement can be an assignment, a function call, a loop, a conditional
statement or even a statement that does nothing (an empty statement).
Statements usually end with a semicolon.
In addition, statements can be grouped into a statement-group by encapsulating
a group of statements with curly braces {...}.
A statement-group is a statement by itself as well.
Making Decisions
If () construct runs a block of code if its test expression is true
Add an else to if() statement, to run different statements when the test
expression is false
use elseif() with if() to test manyconditions
For a given set of if() and elseif() statements, at most one of the code
blocks is run
If statement
it allows for conditional execution of code fragments.
PHP features an if structure that is similar to that of C:
AN INTRODUCTION TO WEB FORMS
To view the output, correct path of the html file has to be typed into the
address box of the web browser .
PHP AND WEB FORMS
Making Web Forms
Useful Server Variables
Accessing Form Parameters
Form Processing with Functions
Validating Data
HTML and JavaScript
Displaying Default Values
Putting it all together
PHP AND DATABASE
Databases
Organizing Data in a Database
Connecting to a Database Program
Putting Data into the Database
Inserting Form Data Safely
Generating Unique ID's
A Complete Data Insertion Form
Retrieving Data from a Database
MySQL without PEAR DB