Jump to content

kents

New Members
  • Content Count

    3
  • Joined

  • Last visited

Community Reputation

0 Neutral

About kents

  • Rank
    Newbie
  1. hi joel24 apologies for the delay in replying i have only just had the opportunity to revisit this and your suggestions have really been a massive help so wanted to say thanks very much for your time! i am left with one small issue which i can't seem to get my head around if yourself or anyone here can give me some pointers it would be much appreciated... for ($i=0;$i<$charsGettingRemoved;$i++){ $randomCharToRemove = getRandomCharToRemove($charsRemoved,$strLength); $charsRemoved[$randomCharToRemove]=substr($word,$randomCharToRemove,1); $word = substr_replace($word,'*',$randomCharToRemove,1); } in your code above i understand that this part $word = substr_replace($word,'*',$randomCharToRemove,1); is where it replaces the randomly removed character with a star '*' instead of a star '*' i would like the removed characters to be replaced with: <input type="text" name="question_1_letters[]" class="inputs" maxlength="1" value="" /> so i can display the full word with a mixture of unremoved characters and inputs where characters have been removed eg B[input]e[input], [input]ees, B[input][input]s, etc etc so the user just has to enter those characters which have been randomly removed, then it goes on to check if there were correct... however if i change the code to for ($i=0;$i<$charsGettingRemoved;$i++){ $randomCharToRemove = getRandomCharToRemove($charsRemoved,$strLength); $charsRemoved[$randomCharToRemove]=substr($word,$randomCharToRemove,1); $word = substr_replace($word,'<input type=\"text\" name=\"question_1_letters[]\" class=\"inputs\" maxlength=\"1\" value=\"\" />',$randomCharToRemove,1); } sometimes it works and other times it seems to replace parts of the input html code breaking it in the process... i assume i'm missing something big here but really not sure how to have the code echo the input html rather than the * many thanks in advance for any help!
  2. thanks very much for taking the time to look at this joel24 much appreciated! i will try to have a go at changing my code to approach it as per your suggestion and see if i have any success one quick question if you have the time, how do i get the above code to take out all the letters if the word is "bees" changing $maxCharsToRemove = 2 to $maxCharsToRemove = 4 seems to skip the first letter of the word...
  3. I have created a word game in php/mysql where users are presented with a randomly selected word in a foreign language and then have to fill in missing letters (which depending on the word length are sometimes randomly removed or sometimes all letters are removed) from the english version of these words into form input fields which are later submitted to the database via a form for checking... The code below works ok except for when a word has more than one instance of a particular letter for examples the word "Bees" For example it will go through find "e" but then replace both instances of the letter "e" with either <input type="text" name="question_1_letter_1" class="inputs" maxlength="1" value="" /> or <input type="text" name="question_1_letter_2" class="inputs" maxlength="1" value="" /> What I really want to happen is for it to just replace once the first "e" it finds so one instance of the letter "e" is replaced by <input type="text" name="question_1_letter_1" class="inputs" maxlength="1" value="" /> and the other instance is replaced with <input type="text" name="question_1_letter_2" class="inputs" maxlength="1" value="" /> here is the main code $one = "question_1_letter_$key1"; $two = "question_1_letter_$key2"; $three = "question_1_letter_$key3"; $four = "question_1_letter_$key4"; $string = Bees; $selected_letter1 = B; $selected_letter2 = e; $selected_letter3 = e; $selected_letter4 = s; $Find = Array($selected_letter1, $selected_letter2, $selected_letter3, $selected_letter4); $Replace = Array( "`<input type=\"text\" name=\"$one\" class=\"inputs\" maxlength=\"1\" value=\"\" />`", "`<input type=\"text\" name=\"$two\" class=\"inputs\" maxlength=\"1\" value=\"\" />`", "`<input type=\"text\" name=\"$three\" class=\"inputs\" maxlength=\"1\" value=\"\" />`", "`<input type=\"text\" name=\"$four\" class=\"inputs\" maxlength=\"1\" value=\"\" />`" ); $New_string = strtr($string, array_combine($Find, $Replace)); echo $New_string; Hope that makes sense! Im still very much a novice php programmer and stuck as to how I can achieve this and may well be overlooking a much simpler solution that I am currently unaware of... if anyone can lend a hand and give me some pointers it would be greatly appreciated!!
×
×
  • 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.