Chapter One: Introduction to PHP
·
PHP is an HTML-embedded scripting language,
meaning that you can intermingle PHP and HTML code within the same file.
o
Starts with a simple web page.
o
The encoding you use in a file dictates what
characters can be represented and therefore, which languages can be used.
o
Example of a PHP script:
§
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0 Transitional//EN"
"http://www.w3.org/
TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html
xmlns="http://www.w3.org/1999/
xhtml"
xml:lang="en" lang="en">
3 <head>
4 <meta http-equiv="Content-Type"
content="text/html;
charset=utf-8" />
5 <title>Basic PHP
Page</title>
6 </head>
7 <body>
8 <!-- Script 1.2 -
first.php -->
9 <p>This is standard
HTML.</p>
10 <?php
11 ?>
12 </body>
13 </html>
·
Anything written within these tags will be
treated by the web server as PHP.
·
PHP files must have the proper extension, which
tells the server to treat the script in a special way, namely, a PHP page.
·
Web servers use .html for standard web pages and
.php for PHP files.
·
When sending data to web browsers, echo may be
used.
Chapter Two : Programming with PHP
Chapter Two : Programming with PHP
Chapter two explores HTML forms and how to handle them. Operators are discussed
as well as loops and arrays.
·
First you create the HTML form itself, then you
create the corresponding PHP script.
·
Examples of form tags:
<form action="script.php" method="post"></form>
<form action="script.php" method="post"></form>
·
Most important form tag is action, which
dictates to which page the form data will be sent. Method is also an attribute.
·
Different inputs are possible such as text boxes
and radio buttons.
·
PHP’s three primary terms for creating conditionals
are if, else, and else if.
·
Every conditional begins with a clause.
·
Validating form data may be achieved by using “isset()”,
which tests if a variable has a value.
·
Arrays are structured as a series of key-value
pairs, where one pair is an item or an element of that array.
·
PHP supports two kinds of arrays: indexed, which
uses numbers and keys, and associative, which uses strings as keys.
·
Examples of loops:
o
While:
§
while (condition) {
// Do something.
}
·
For:
o
for (initial expression; condition;
closing expression) {
// Do something.
}
Chapter Three: Creating Dynamic Web Sites
Dynamic
Web sites, as opposed to the static ones on which the Web was first built, are
easier to maintain, are more responsive to users, and can alter their content.
·
Including multiples files are used to extract
the HTML from the PHP or to separate out commonly used processes.
·
PHP has four functions for incorporating
external files: include(), include_once(), require(), and require_once().
·
An absolute path references a file starting from
the root directory of the computer.
·
A relative path uses the referencing (parent)
file as the starting point.
·
The include() and require() functions are
exactly the same when working properly but behave differently if they fail.
·
To have one page both display and handle a form,
a conditional must check witch action (display or handle) should be taken.
·
A GET request is the first request, which loads
the form.
·
The second request is a POST request method,
that submits the form.
·
A sticky form is a standard HTML form that
remembers how you filled it out.
·
The value attribute is used to preset what’s entered
in a text input.
·
To preset the status of radio buttons, add the
code checked=”checked” to their input tags.
·
To preset the value of a textarea, print the
value between the textarea tags.
·
To preset a pull-down menu, add selected=”
selected” to the appropriate option.
·
PHP has the capability to allow users to define
their own function. It can be any combination of letters, numbers, and the
underscore, but it must begin with either a letter or the underscore.
No comments:
Post a Comment