PHP Data Manipulation
Arrays
- An online array reference.
Be sure to look through the array functions.
- $numbers = array();
- $numbers[0] = 2006;
- echo $numbers[0];
- unset($numbers[0]);
- foreach ($numbers as $number) {}
- foreach ($numbers as $index => $number) {}
- is_array() -- Variable Handling Functions
- count()
- max() -- Mathematical Functions
- min() -- Mathematical Functions
- array_reverse()
- sort()
- rsort()
Strings
- An online string reference.
Be sure to look through the string functions.
- strlen()
- sprintf() -- returns a formatted string
- printf() -- prints a formatted string
- strtolower() -- convert to lowercase
- strtoupper() -- convert to uppercase
- strcmp() -- string compare
- substr() -- substring
- strpos() -- position of a substring
- str_replace() -- string replace
Regular Expressions
- An online regular expression reference.
- Note: php also supports perl-compatible regular expressions.
- ereg() -- case sensitive
- eregi() -- case insensitive
- one character wildcard - .
- to match a period - /.
- character list: [aeiou] or [0-9]
- start of string anchor: ^
- end of string anchor: $
- to match 0 or 1 times: ?
- to match 0 or more times: *
- to match 1 or more times: +
- to match 3 times: {3}
- to match between 3 and 5 times: {3,5}
- to group characters: (abc)
- to provide alternatives: |
- logical not: ^
Dates and Times
Mathematical Functions
Lecture Code
Take a look at this
file reference
manual. Write a program named gettysburg.php that reads in
this input file
and generates the content of this
document exactly.
Solution
The gettysburg.php file that we
covered during lecture.
Laboratory
Do something interesting and non-trivial that uses some of today's material.
If you are a Montana State student, demonstrate it during
today's lab period. If you are a University of Leipzig
student, either demonstrate it during today's lab period or
e-mail it to Sebastian (loewe AT uni-leipzig.de) no later than
the end of the day.