I have a txt file with paragraphs in it … Some of the sentences have the following tags in it <#noun>, or <#verb>, etc …
I need to parse the file in php and display the content in between the tags to the user.
The user can fill the the words in text box, and the story will be displayed with the new words instead of the tags.
I have spent lots of time on google and only got more confused.
I would really appreciate if anyone can put this into php code, and I can play around as needed.
Here is an example of the text file:
One day, I was walking through the <# adjective #> part of
Toronto when I ran into a huge stack of <# plural noun #>!
It was the most <# adjective #> sight I had ever seen. I tried
to call my best friend, <# proper noun #>, to tell <# him/her #>
about it but all of the phone circuits were busy.
Ooh, I remember these from high school writing them on a TRS 80. Here’s a basic one that handles two variables. Using it as a reference see if you can build the mad lib you’re looking to build.
Name this file “madlib.php”
<html>
<head>
<title>My MadLib</title>
</head>
<body>
<h1>MadLib</h1>
<?php if (isset($_POST['action']) && $_POST['action'] == "show"): ?>
<p>Hello, I am a <?php echo $_POST['adj'] ?> computer that owns a <?php echo $_POST['noun'] ?>.</p>
<?php else: ?>
<form action="madlib.php" method="post">
<input type="hidden" name="action" value="show">
<p>An adjective: <input type="text" name="adj"></p>
<p>A noun: <input type="text" name="noun"></p>
<p><input type="submit" value="Go!"></p>
</form>
<?php endif ?>
</body>
</html>
I dont see how you are parsing the text file. I need to parse the text file for the content between the tags. And dynamically generate the text inputs. Then fill in the blanks and show the story to the user on page 3.