Jump to content

Search the Community

Showing results for tags 'strtr'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Donation Link

Found 1 result

  1. 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.