Exercises for Programmers part 1
Last updated: October 24, 2022
Introduction
Here’s a supplemental video to reinforce the ideas for these first exercises.
A utility function
function formatCode($code) {
echo "<code class='show-code'>";
echo '<pre>';
print_r($code);
echo '</pre>';
echo '</code>';
}
This will be helpful!
saying-hello.php
<?php
/* initializing the data */
$name = "Bobbo head";
/* handing user input */
$formSubmitted = isset($_POST["submitted"]);
if ($formSubmitted) {
$name = $_POST["firstName"];
}
/* calculations */
$greeting = "Hello, $name, nice to meet you!";
?>
<form method='POST'>
<field>
<label for="fn">What is your first name?</label>
<input id="fn" type="text" name="firstName">
</field>
<button type="submit" name="submitted">Submit</button>
</form>
<output>
<!-- feedback -->
<p><?=$greeting?></p>
</output>
There are a few loose ends to tie up here…
Do you know what they might be? Have you tried it out in all of the scenarios that might happen?