Personalize a theater notice
Before you start this intermediate track
Variables, function calls, and key-value arrays. These examples run as small scripts.
Guided code reading and debugging. Runnable coding challenges are available in JavaScript, Python, and SQL.
Understand it, then try it.
A theater notice repeats the same seat placeholder in two places. str_replace takes the text to find, its replacement, and the original string, in that order. It returns a new string with every matching occurrence replaced. Keeping that result in notice makes the finished wording available for printing.
<?php$template = "Seat {seat}; keep stub for {seat}.";$notice = str_replace("{seat}", "B12", $template);echo $notice, "\n";Each mission is a complete independent PHP 8 or later command-line script, including the opening <?php tag. Save as quest.php and run php quest.php. Output is plain text; no web server is required.
Track the values line by line. Predict the result before running this example in your own editor.