How to find words from .txt file using specific pattern

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • firian
    New Member
    • Jul 2010
    • 2

    How to find words from .txt file using specific pattern

    It's my first post here, so hi all.
    Anyway, I am trying to work this out, but can't do this alone. I have a specific line of text, I already replaced it with something more user-friendly using this piece of code:
    Code:
    <?php
    
    $algorytm = ",,D-,,R,-,,T,-,P,,-F,,,¤,P,,-,I,,-,,,F-,,,E¤,,,G-,,T,-,,S,-O,,,-,,E,¤,,,E,-D,,,,-,P,,,-R,,,,-,,N,,¤,,,S,-,,A,,-,,L,,¤,,,,M-,,,A,-,,,S,-,,F,,-,,,B,¤,,,,G-,,,T,-,E,,,";
    
    $algorytm2 = str_replace(",", "?", $algorytm);
    $algorytm3 = str_replace("¤", "-", $algorytm2);
    $algorytm4 = str_replace("-", "<br>", $algorytm3);
    echo $algorytm4;
    
    ?>
    The result is here: http://p.netserwer.pl/words/
    The pattern itself always contains 30 lines that contains words made from 3, 4 or 5 letters. There is always only 1 letter assigned, the ? are wildcards and anything can be placed here. What do I need ? - example:

    ??D RED
    ??R? BIRD
    ??T? BITS

    I am trying to assign a word to every line next using the pattern where ??D is any 3-letters word that ends with D etc. I have also made wordlists:
    http://p.netserwer.pl/words/3.txt
    http://p.netserwer.pl/words/4.txt
    http://p.netserwer.pl/words/5.txt

    To be honest, I am not a good programmer and have no idea how to make it. Any help or advice will be appreciated.
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    So what you have to do is convert your 30 or so patterns to expressions. Then for every line in your words file check to see if any of the words match any of the pattern.

    Here's an example of a regular expression for one of your patterns:

    Code:
    if(preg_match('[A-Z][A-Z]D',$word,$match)
    {
      echo $match[0];
    }
    so just replace your question marks with [A-Z], put it in pregmatch function and compare to each of your words in your word file.

    I see each of your word file contains 3 letter, 4-letter, and 5-letter words, so I guess you should organize your patterns this way too: compare 4 letter patterns with the 4.txt file, etc.

    Good luck,


    Dan

    Comment

    • firian
      New Member
      • Jul 2010
      • 2

      #3
      This is what I get so far: http://p.netserwer.pl/words/

      Sample patterns to input in textform:
      ,,D-,,R,-,,T,-,P,,-F,,,¤,P,,-,I,,-,,,F-,,,E¤,,,G-,,T,-,,S,-O,,,-,,E,¤,,,E,-D,,,,-,P,,,-R,,,,-,,N,,¤,,,S,-,,A,,-,,L,,¤,,,,M-,,,A,-,,,S,-,,F,,-,,,B,¤,,,,G-,,,T,-,E,,,

      It's just a sample of 30 patterns, they will change, so I can't code anything for specific pattern. That's why I need something that will not be defined for specific pattern like ??D - but for everything that I input.

      //edit
      I found this: http://www.thewordfinder.com/classic/crossword.php
      I need something similar, you input 1 pattern here and get matching words. I need same thing for list of 30 patterns, where I will have 1 word matched.
      Last edited by firian; Jul 22 '10, 10:26 PM. Reason: edited

      Comment

      Working...