Jump to content

creating madlibs in php


kavkazi

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.