This is material from Chapter 3 in the text. I've left a few
- A PHP is interpreted by the server.
- The PHP file is stored on the server with extension .php.
- The server sends the contents
of the file, except the portions wrapped in <?php ?>.
- Those contents are executed, and the output is sent.
- The un-wrapped portions are HTML, and the PHP should generate HTML.
- The example below runs code that prints a string constant.
[ Hello, World! Source ]
- HTML and CSS are declarative languages, but PHP is procedural.
- Performs steps in order.
- Updates values may change over time.
- The point is to create pages which vary and can respond to inputs from
the user, or display data stored on the server.
Hello, World That Pays Attention To It
- Basic Syntax.
[ PHP Basics Source ]
- Comments, /* */ and //.
- Variables hold values. Marked with $
- Instructions are “statements,” and end with ;.
- The = makes an assignment, does not test for equality.
- Variables may be used in expressions.
- Values have types.
- ' and " each create strings.
- Double quotes “interpolate” embedded variables; singles don't.
- The multi-line form starts with <<<ANY
- Use the three less-thans, then any marker you like.
- Ends when it sees the marker again.
- The . operator concatenates string. (Java programmers
- PHP is dynamically-typed, and variables need not be declared.
- Type conversion is very fluid, and explicit casting is rarely needed.
[ PHP Arrays Source ]
- Collections of variables.
- Each designated by a name or number.
- The phpinfo function. Generates a complete HTML page.
[ PHP Info Source ]
[ Varible Echo Source ]
- Variables provided by the system when the script runs.
- These are string-subscripted arrays, having names that are
all-caps except they start with underscore.
- The Phpinfo shows you what is available.
- Be very carful when printing things that come from the user.
the browser, or possibly PHP that will run on the server.
- Use htmlentities to prevent this.
- Queries. An important source of input to a PHP script is query information
in a URL. ?name1=value1&name2=value2
[ Send to info page: phpinfo.php?count=10&joe=boss ]
[ Send to query echo page: query1.php?joe=17&alice=sick&bill=199 Source ]
[ Or this: query1.php?joe=missing&bill=0&alice=out+of+the+country ]