Chapter 4 Lab
Create a string variable to contain one string that will be printed in bold text on two lines as:
"Ouch! That's not nice," snickered Mrs. O'Connell.
"You mustn't do that, Mr. O'Connell."
What does the following code print?
print ("What a <b>perfect</b> day."); print ("3" + 2); print ("5 dogs" + "6 cats" . "10 birds"); print ("<pre>\t\tIt's been real!\n</pre>"); print ("\t\tLater, dude.\n");
Create four variables that contain an integer, float, string, and boolean value. Print the value of each variable and its data type in an HTML table. Use gettype().
In Exercise 1 you created the following PHP output. Now we will rewrite this script to include user-defined variables. Where you see < > in the example, input your variable values.
Print the output in the browser. Can you format the output so that a dollar sign appears before the money values and format the numbers with a precision of two places to the right of the decimal point (e.g., $410.00)? Hint: See http://www.htmlite.com/php011.php.
Check to see if the variables are set (isset()) before displaying them.
Set variables as follows;
$sales = 190000; $rent = 25000; $salary = 37500; $supplies = 410; $total = $rent + $salary + $supplies; // Addition $operating_income = $sales - $exp_total; // Subtraction $net_income = $operating_income * 0.60; // Multiplication Book Store Operating Costs ============================================ Sales: <print variable values here> Expenses: Rent: < > Salary: Supplies: Total: < > Operating income: < > Income after taxes (net): < > =============================================
Use the shortcut PHP tags, <?= ?>, within the HTML document to display the variables in the previous exercise. (Check the php.ini file to see if shortcut tags are allowed and if set to "Off", turn them "On".)
Create an HTML form that contains three text boxes, one for the user's name, one for his cell phone number, and one for his e-mail address. Write a PHP script to display the output.
Rewrite Exercise 4 so that the user enters input into an HTML form, and write a PHP script to process the form and display the output as it did in Exercise 4.
Write a PHP script that displays the values entered into the form fields. Add a constant to the following script that will define a COPY_RIGHT constant containing your SITE_NAME with the copyright symbol appended (concatenated) to it. Display the constants and their corresponding values in an HTML table. Hint: See http://www.desilva.biz/php/constants.html.
<?php> // Define your site name, since it does NOT change // anywhere within your script. define( 'SITE_NAME', 'Your site' ); // Define the current year, possibly to use in your copyright // statement or for 'date' calculations. define( 'THIS_YEAR', date('Y') ); ?>