Rewrite the print statement in the final version of handle_post.php (Script 5.7)
ID: 3913094 • Letter: R
Question
Rewrite the print statement in the final version of handle_post.php (Script 5.7) so that it uses single quotation marks and concatenation instead of double quotation marks.
Files attached below:
handle_post.php
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Forum Posting</title>
</head>
<body>
<?php // Script 5.7 - handle_post.php #6
/* This script receives five values from posting.html:
first_name, last_name, email, posting, submit */
// Address error management, if you want.
// Get the values from the $_POST array.
// Strip away extra spaces using trim():
$first_name = trim($_POST['first_name']);
$last_name = trim($_POST['last_name']);
$posting = trim($_POST['posting']);
// Create a full name variable:
$name = $first_name . ' ' . $last_name;
// Get a word count:
$words = str_word_count($posting);
// Take out the bad words:
$posting = str_ireplace('badword', 'XXXXX', $posting);
// Print a message:
print "<div>Thank you, $name, for your posting:
<p>$posting</p>
<p>($words words)</p></div>";
?>
</body>
</html>
posting.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Forum Posting</title>
</head>
<body>
<!-- Script 5.1 - posting.html -->
<div><p>Please complete this form to submit your posting:</p>
<form action="handle_post.php" method="post">
<p>First Name: <input type="text" name="first_name" size="20" required></p>
<p>Last Name: <input type="text" name="last_name" size="20" required></p>
<p>Email Address: <input type="email" name="email" size="30" required></p>
<p>Posting: <textarea name="posting" rows="9" cols="30" required></textarea></p>
<input type="submit" name="submit" value="Send My Posting">
</form>
</div>
</body>
</html>
thanks.php
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Thanks!</title>
</head>
<body>
<?php
/* This is the page the user sees after clicking on the link in handle_post.php (Script 5.5).
This page is not formally developed in the book.
This page receives name and email variables in the URL. */
// Address error management, if you want.
// Get the values from the $_GET array:
$name = $_GET['name'];
$email = $_GET['email'];
// Print a message:
print "<p>Thank you, $name. We will contact you at $email.</p>";
?>
</body>
</html>
Your modifications to the handle_post.php file should give an output like this:
Explanation / Answer
print 'Thank you, $name, for your posting:'
' '.'$posting'
.' '.'($words words)';
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.