Our first look at string handling in php, and some date / time functions. Topics include:
formatting date values
formatting time values
Note: I strongly suggest you view all our videos in full screen mode: click the icon
in the lower right corner of the video area (it shows four arrows pointing
to the corners of the screen). When you are done, the Esc ("escape") key
returns you to regular mode.
Lesson 8: string handling Part 1: strings and date / time
This exercise is primarily focused on creating file names and constructing date / time strings
We'll start by declaring variables "$today" and "$now", using the format patterns
of your choice, then setting up instructions to format first name and last name
to have the structure discussed in lecture, ending up with the notification page
to the user reflecting the date and time of the sign up request and echoing
the generated user filename.
Open your cgis/AddTraveler.php and add the following pieces of code:
In the general comments at the top, after "invoked using POST from signUp.shtml",
add a comment like:
build $userFile = $fname.$lname.'.shtml' with no spaces, commas, slashes, apostrophes or periods
In the comment about building a response page, add the phrase "and the date and time"
After the declare of $addr_back, add a declare of $chars as in the lecture
After the declare of the mail arguments, add declares for $today and $now using format
patterns of your choice
After the declare of $first, add three lines of code to create $fname with none of characters listed
in $chars and with first letter uppercase and rest lower case
After the declare of $last, add code similar to the handling above to create $lname
Note: the variables $first and $last will continue to hold the first name and last name
as entered by the user; $fname and $lname are to be used in generating file names
After the declare of $msg, create $userFile as defined in lecture
In the body of the page generation code, after the 'echo' that displays the user's address,
add an 'echo' of a <p> element containing "We noted your request arrived at $now on $today."
Then add an 'echo' of a <p> element containing
"The name processing has resulted in a first name of $fname and last name of $lname"
If $ties is empty (== ""), assign "None specifed" to $ties
Use a <p> tag to display the value in $ties
Save your updated AddTraveler.php file and upload this version to your cgis/ directory
Test your new php by going through the sign up page using a variety of names
Validate the generated values for $fname and $lname and the format for the $today and $now variables
A look at how to validate data in your php CGI code. Topics include:
How to invoke a CGI from another server
How to enter malicious data
How to detect incorrect or malicious data
How to respond to incorrect or malicious data
The 'exit' statement
The 'goto' statement, and labels
Lesson 8: string handling
Part 2: php data checking
if you would like additional information.
We would love to see your comments and
recommendations for our site.
of where you are on the site, but we do not
leave cookies on your site; we do not track
your visits; we do not disseminate any
information about you because we do not
gather any information about you.