Back to DFS's Workshop Page
Back to Agenda Page
In order to test a script, it is often most beneficial to hardset variables so that they contain known values.
We will use the area-of-a-triangle problem for this demonstration.
The following code should be saved in a file called trihardset.php in ~YOURID/public_html/test_php/.
<!-- trihardset.php --> <html> <head> <title>Calculating the Area of a Triangle: Result</title> </head> <body> <?php // This script illustrates how to process information // hardset in a script for testing purposes // Hardset the dimensions dimensions $b (base) and $h (height) // of the triangle $b = 5; $h = 7; echo "<h1 align=\"center\">Calculating the Area of a Triangle: Result</h1>\n"; // Print the base echo "<p>b is $b.\n"; // Print the height echo "<p>h is $h.\n"; // Calculate and print result $A = $b * $h / 2; echo "<p>The area of a triangle with a base of $b and a height of $h is $A.\n"; ?> </body> </html>