<?php
include('../includes/header.php');
// code
error_reporting(E_ALL); // set error reporting to all
echo('<h1>My String Example</h1>');
$step = isset($_POST['step']) ? $_POST['step'] : 0;
$animal = isset($_POST['animal']) ? $_POST['animal'] : '';
$place = isset($_POST['place']) ? $_POST['place'] : '';
// filter all input taken from the Browser
$step = htmlentities($step);
$animal = htmlentities($animal);
$place = htmlentities($place);
if ($step == 0) // first time into this form
{
?>
<form action="strings5.php" method="POST">
<label for="animal">Input an Animal: </label>
<input type="text" size="36" id="animal" name="animal" value="">
<br><br>
<label for="place">Input a Place: </label>
<input type="text" size="36" id="place" name="place" value="">
<br><br>
<input type="hidden" name="step" value="1">
<input type="submit" name="submit" value="Submit">
</form>
<?php
} else // create the string
{
$sentence = "The {$animal} went to the {$place}.";
$length = strlen($sentence);
$tcount = substr_count($sentence, "t") + substr_count($sentence, "T");
$rot = str_rot13($sentence);
echo($sentence . nl2br("\n\nThe sentence above is {$length} characters long.\nThe letter t appears {$tcount} times.
\nThe ROT13 cipher of the sentence is: {$rot}\n\n"));
}
// provide a form to try again
if (!$step == 0){
?>
<form action="strings5.php" method="POST">
<input type="hidden" name="step" value="0">
<input type="submit" name="submit" value="Try Again">
</form>
<?php
}
include('../includes/footer.php');
?>