Greetings, students. This is the final Exam Practice Test. The actual exam will have 10 questions, whereas this practice test contains only five.
- When completing this practice test, try to answer the questions without using online resources, since you will not be allowed to use a computer during the actual exam.
- You may want to have a few sheets of (good ol’ fashioned) pencil and paper handy, since you’ll be completing the examination on paper.
Refer to the study guide for topics that you should be familiar with before beginning this test.
If you have any questions, please let me know.
Practice Test
Fill in the blanks:
- A _____________________ is preceded by a dollars sign ($) symbol and stores a value.
- If/Else and If/Else/Elseif are examples of _____________________ statements.
- Operations consist of ____________________, which manipulate ________________.
Write a function that accepts two arguments, and then performs the following operations on the variables:
- Test if the arguments are a string of at least two characters
- Concatenate the two strings together (in order)
- Reverse the string (strrev())
- If the string is longer than ten characters, convert it to lowercase (strtolower())
- If not, convert it to upper case (strtoupper())
- Return the result
Analyze the following code, and write what the HTML output will be:
<?php
function fixNumber($input)
{
if (!is_numeric($input) || strlen($input) < 4)
return $input;
//sttrev() reverses the string
$input = strrev($input);
$x = 3;
while($x < strlen($input))
{
$beforeComma = substr($input, 0, $x);
$afterComma = substr($input, $x);
$input = $beforeComma . "," . $afterComma;
$x+=4;
}
//strrev() reverses the string (again)
$input = strrev($input);
return $input;
}
$states = array();
$states["Georgia"] = array("Capital" => "atlanta", "sqMiles" => 59425);
$states["Florida"] = array("Capital" => "tallahassee", "sqMiles" => 65795);
$states["Virginia"] = array ("Capital" => "richmond", "sqMiles" => 42774);
$states["Maine"] = array("Capital" => "augusta", "sqMiles" => 33414);
ksort($states);
foreach($states as $stateName => &$stateStats)
{ $stateStats["sqMiles"] = fixNumber($stateStats["sqMiles"]); }
echo "<ul>";
foreach($states as $stateName => $stateInfo)
{
echo "<li><strong>$stateName</strong> <em>(". ucfirst($stateInfo["Capital"]) .")</em> -
{$stateInfo["sqMiles"]}</li>";
}
echo "</ul>";
?>
Below is the HTML code for a form. Study it closely:
<form name="myForm" method="post" action="processme.php">
<h1>What is your favorite food?</h1>
<p>Name <input type="text" name="userName" /></p>
<p>Age <input type="text" name="age" /></p>
<p>Favorite Food <input type="text" name="favFood" /></p>
<p>Pass Phrase <input type="password" name="userName" /></p>
</form>
Write PHP code that processes the form. Adhere to the following specifications:
- Validate the input. All fields are required.
- If there are any missing fields, use die() to terminate the script.
- Print the name of each field using an ordered list (<ol>).
Identify four problems that will cause parse errors within the script:
<?php
function printNotice($notice == null)
{
/Print any notices
if ($notice == null && isset($_GET["notice"]))
$theNotice = $GET["notice"];
elseif ($notice == null & isset($_POST["notice"]))
$theNotice = $_POST["Notice"];
elseif($notice !== null)
$theNotice = $notice;
if(iset($theNotice))
echo "<div class=\"notification\">$theNotice</div>";
}
?>
Posted on April 21st, 2008 by Casey
Filed under: General Postings | No Comments »