CS 328 - Week 7 Lecture 1 - 2016-02-29
**************************
* Beginning of our intro to PHP
**************************
* (whirlwind tour, anyway...!)
* many languages CAN be used on the application
tier(s) --
PHP is merely ONE of them
* goal: to cover a useful subset of PHP
to get you started designing and implementing
small n-tier applications
(with and without sessions)
that happen to use PHP on an application tier
* note that:
php -version
...can let you know what version of PHP
is running where you are,
and today, on nrs-projects, that version is
5.3.3
* what is PHP?
* scripting language
* created by Rasmus Lerdorf in 1995
* acc. to course text,
originally stood for: Personal Home Page
BUT as the language was expanded, this
was CHANGED to now stand for:
PHP: Hypertext Processor <- yes, a recursive
acronym
* PHP is another language that CAN be
embedded within an HTML document...
BUT!! where that code is EXECUTED is
*different* than where, say,
HTML or CSS or client-side JavaScript
* it is EXECUTED ON THE APPLICATION TIER,
and NOT on the client tier!
* (client tier gets the RESULT of the
executed PHP -- NOT the PHP code
snippets themselves...)
* much of its syntax is borrowed from
C, Java, and Perl, with some unique
PHP-specific features thrown in;
* crowdsourced language -- SOMETIMES
there are MULTIPLE syntaxes for the
same thing...
* goal - to help web developers write
dynamically-generated pages
* in THIS COURSE,
here are our two acceptable PHP tags:
<?php
statement;
...
statement;
?>
<?= your_php_expression ?>
^ the value of this expression goes into
the resulting document!
(this variant is called an expression tag)
* ONE place for PHP is to put PHP code within
such tags embedded in an HTML document
whose suffix is
.php
^ when you put a URL in a client's browser
that ends in .php, the web server
passes on this request to a PHP Preprocessor
running on the application tier --
it executes the requested document,
and RETURNS the result to the web server
to return to the client's browser
* one of PHP's definite strengths is its robust
collection of require and include functions --
two of these include:
require_once
include_once
these expect a string representing a file name,
and they result in that file's contents being
put into the document AT that point
the _once versions make sure a particular file's
contents are not inserted more than a once into
a single document;
use require_once to get a FATAL error if the file
to be inserted cannot be found,
use include_once to get just a WARNING if the
file to be included cannot be found
* demo'd in hello.php
* variables - they start with a $ followed by a
characters (and then 0 or more letters, digits,
underscores -- not sure what other special
characters are supported)
* loosely-typed -- you can simply set a variable
to a value, and it exists
* PHP supports variable interpolation --
' ' and " " may BOTH be used to indicate
a string literal,
BUT!!! IF that string contains a variable,
it behaves differently in ' ' vs. " "
* inside ' '? $ is not special, so $moo is simply the
characters $ m o o
* inside " "? $ *is* special, and $moo would get REPLACED
by its current value (variable interpolation)
* By the way: you concatenate with . in PHP
(thanks, Perl...!)
* CLUNKY demo of . and ' ' vs " " in hello.php, also