CSCI 3355 Topic Outline in "Semi-Chronological" Order
This page may be continually revised/updated as the course
progresses.
Classes begin in this course on Tuesday, January 9, 2024, and you should make a special effort to be present online for the first class and recitation/lab.
The assigned text for this course is the online zyBook, but additional material will include online documents, as well as sample files and code from various sources. Material presented and discussed in our live online sessions will not necessarily appear on the course website, but since you will be responsible for everything covered in class and/or recitations, it will be important that you attend both classes and recitations.
Of course you will need to learn more about HTML5, CSS3 and JavaScript as the course progresses and you work on your website development. Of particular interest and utility are the following:
Things you should know about our development environment:
ps.cs.smu.ca
server, with a username like u##
.
This machine is actually a virtual Linux server running Ubuntu, and has
all the software we will need: PHP, phpMyAdmin, MySQL, MongoDB, and
(possibly) NodeJS. You will be assigned your account at the appropriate
time.
Client-side (Windows and/or Mac) software:
Server-side (Linux) software:
nano
editor is a simple
one available at the command line, and if you are a Vim user you can
expect to find it there as well. But ... by far the best option is to
install Visual Studio Code on your local machine and use it to connect to,
and work directly on, the server.
ispell filename.ext
The following material on PHP and MySQL is directly relevant for the development of your website. There are zyBook chapters dealing with these topics and other chapters or chapter subsections contain additional material that you may need or find helpful as well, but getting comfortable first with PHP and then with MySQL is what you should start working on immediately, since both of these will be crucial throughout the course and your website development.
string uses single or double quotes, but double quotes
allow variable interpolation whereas single quotes do
not.
--The string concatenation operator in PHP is the period (.),
not the plus sign (+) that you might expect.
--The double quote, single quote, newline, tab, dollar sign and
backslash can all be escaped within double quotes, but only single quote
and backslash can be escaped within single quotes.
--A "hard newline" (entered by pressing Enter in an editor) can also
be included in a PHP string.
--Outputting the built-in constant PHP_EOL will output the correct newline character for the current platform.
integer, float, boolean (with values TRUE and FALSE), array, object, null (with value NULL) and various resource types such as files).
Predefined constants: INF, TRUE, FALSE, PHP_EOL
Note that when a string is compared to a number with any comparison operator besides the identical and non-identical operators, the string is first converted into a number and then compared. When two strings are compared, if the strings being compared start with a numeric character (a digit or plus or minus sign), the numerical strings are first converted into a number before the comparison, which is done character by character. Good practice is to use === and !== when comparing strings for equality.
Note as well that when a string appears in an arithmetic expression, the string is first converted into a number before the expression is computed. If a string can't be converted to a number, it is converted to 0. Strings with leading text are converted to 0, while in strings with trailing text the trailing text is ignored.
And note that && has a higher precedence that ||, but generally it is best to use parentheses to avoid the possibility of a logical expression being evaluated incorrectly.
Access array values (for reading or writing) using square brackets [ ]
with an index or a key. If adding a new value with empty brackets, the next highest index is used. Either of the following loops will access all of the values in the array:
foreach ($indexedArray as $value) {} or
foreach ($assocArray as $key => $value) {}
print_r($a) prints the array
count($a) returns the number of elements in the array
array_push($a, v1, v2, v3) adds values to the end of the array
array_pop() removes the last element of the array
array_unshift() and array_shift() add/remove values to/from the front of an array
PHP also has multidimensional arrays: $a = [k1=>$a1, k2=>$a2, k3=>$a3]
Array sorting functions:
sort() sorts an indexed array in ascending value order
asort() sorts an associative array in ascending value order
ksort() sorts an associative array in ascending key order
rsort(), arsort(), and krsort() perform similary, but in reverse order
$s the (0-based) array that contains the command-line inputs when running PHP at the command line, including the script name at index 0.
The list() function can assign the values of an array to individual variables given as its parameters.
Superglobal arrays are used to access web information from PHP scripts
on web pages:
$_SERVER
$_SESSION
$_GET
$_POST
$_COOKIE
$_REQUEST
These are special PHP arrays used to access server and web page data from PHP scripts:
$_FILES
$_ENV
$_GLOBALS
PHP has local (to-the-function) scope and global (access-from-all-functions) scope but to access a global variable a function must explicity modify the name of the global variable using the global keyword. PHP also static scope, which permits a function to retain the value of a local variable between function calls if that variable is modified with the static keyword.
Function names are case-insensitive and both underscores and camel case are used, though PHP itself uses underscores.
Function parameters may have default values.
Pass-by-value is the default parameter-passing mechanism in PHP, but placing an & before a parameter name makes it a pass-by-reference parameter.
A PHP function can have a variable-length argument list. That is, function name(...$a) is a function that can be called with any number of arguments, all of which will go into the array $a, and can then be accessed from that array in the body of the function.
preg_match($r, $s)
, preg_match($r, $s, $m)
, preg_match_all($r, $s, $m)
preg_replace($r, $replacement, $s)
, preg_grep($r, $s
), preg_split($r, $s
)
filter_var($s, SOME_FILTER_CONSTANT)
isset()
, trim()
, htmlspecialchars()
filter_var()
is just one of several filter functions
count($a)
or sizeof($a)
, in_array($a, value)
,
array_keys($a)
, array_values($a)
array_unique($a)
, array_count_values($a)
, array_fill_keys($keys_array, value)
explode(separator, $a)
, implode($a)
array_push($a, v1 [, v2 ...])
, array_pop($a)
array_shift(a$)
, array_unshift($a, value)
sort($a)
, rsort($a)
, asort($a)
, arsort($a)
, ksort($a)
, krsort($a)
print_r($a)
, list($a)
include()
, require()
fopen("path/file", "mode")
, fclose(file_handle)
, unlink("path/file")
fwrite(file_handle, output)
fread(file_handle, num_bytes)
, feof()
file_get_contents("file/path|url")
, fgets(file_handle, num_bytes)
json_decode(JSON_file_handle)
, json_encode($PHP_array)
phpinfo()
, var_dump()
, die()
, exit()