kavkazi Posted November 24, 2010 Share Posted November 24, 2010 I am trying to create a madlibs game .. 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 am new to php. Any help greatly appreciated. Thanks in Advance, Vladimir Quote Link to comment Share on other sites More sharing options...
Rifts Posted November 24, 2010 Share Posted November 24, 2010 create a form with 5, 10, 500 text input fields whatever you want have them be named input1, input2, etc or whatever u want in the madlib just echo the posted value "I was riding my <?= $_POST['input1'];?>, when suddenly a huge ..." also make sure to mysql escape the posted values before echoing them Quote Link to comment Share on other sites More sharing options...
kavkazi Posted November 24, 2010 Author Share Posted November 24, 2010 Thanks for your reply Rifts .. but im looking for something else. I need to parse the story for the tags <# ... > The story is in a text file, and it can be replaced with another sotry. Therefor i need to parse the tags and create the form inputs dynamically .. the php should read the story from a txt file .. show all the tags in the story to the user, with ability to provide words in that place. And finally display the story with the replaced words to the user. Thanks Quote Link to comment Share on other sites More sharing options...
objnoob Posted November 24, 2010 Share Posted November 24, 2010 You'd wanna MySQL Escape, and HTMLspecialchars anything going into the database. You'd only have to htmlspecialchars anything being echo'd to the browser. PHP has a very good set of built-in string parsing functions. Do a google search for parsing strings in using PHP. Quote Link to comment Share on other sites More sharing options...
kavkazi Posted November 24, 2010 Author Share Posted November 24, 2010 sorry, 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. I don't understand why i need to use sql escape if i dont have a database or table.. its just a txt file with some parapgraphs. Thanks for your help. Quote Link to comment Share on other sites More sharing options...
objnoob Posted November 24, 2010 Share Posted November 24, 2010 It would be hard for someone to make PHP code to parse your txt file when we not know how your text file is exactly laid out. We know you're not using a database, I just had to blert that out so it would stick with you when you do decide to work with Databases. Since you are accepting user input and showing it on the screen you should be aware of XSS Cross Site Scripting! You should always make sure to validate that the user input has no harmful garbaleegook before doing whatever with it. Quote Link to comment Share on other sites More sharing options...
kavkazi Posted November 24, 2010 Author Share Posted November 24, 2010 Attached is an example of a text file [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.