SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Mar 2012
    Location
    Norway
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP regex, character match word

    Hi

    This is a bit embarrasing. Maybe i'm tired..but:

    If I want to match these characters: abc
    with these "words": abc cba cab acb bac

    How do I do this in regex? Let's say I got an array with words, and I want my 3 characters to match any word that contain these 3 characters.

    Thanks for any help.

  2. #2
    SitePoint Evangelist smftre's Avatar
    Join Date
    Dec 2008
    Location
    London
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please elaborate your question, I don't fully understand what you are asking and I'ms ure nobody else is as there's been post views but no replies..
    Statvoo.com The Website Traffic Monitor
    The best way to monitor traffic to your sites for free!


    Web Development London UK We make web 3.0 applications

  3. #3
    SitePoint Member
    Join Date
    Mar 2012
    Location
    Norway
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright. I'll try once more:

    I can use wordfeud/scrabble as example.

    If I got these letters: O L N R A O P
    And I want to find words from an array (wordlist) that contains letters from above.

    From 'O L N R A O P' I can get the word Pool, Loan and maybe others. How do I do this?


    //Load array
    //Letter input
    //Search array for words that contains the letters. Ex 'O L N R A O P' match the word POOL
    //Put this in a foreach loop to spit out every word that matches letters from the input

    Is this the right approach ? Can I do this with regex, or is there any other way ?


    I'm not making any wordfeud/scrabble cheating engine.. but I just want to learn how to do this. And probably using this for other script(s).

  4. #4
    SitePoint Evangelist smftre's Avatar
    Join Date
    Dec 2008
    Location
    London
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink

    Seems you're looking to make something like this? http://grecni.com/texttwist.php

    It uses a wordlist/dictionary file to see all possible words a bunch of characters can make up.

    Try something like this to show all the letters to work with and then plug it into your wordlist:
    PHP Code:
    $word "lpoo";
    foreach (
    count_chars($word 1) as $i => $val) {
    echo 
    chr($i)."<br/>";

    Statvoo.com The Website Traffic Monitor
    The best way to monitor traffic to your sites for free!


    Web Development London UK We make web 3.0 applications

  5. #5
    SitePoint Member
    Join Date
    Mar 2012
    Location
    Norway
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, something like this!

    hmm, one problem with that code is that it removes letters that is more than 1.

    It echo's:
    l
    o
    p

  6. #6
    SitePoint Member
    Join Date
    Mar 2012
    Location
    Norway
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Example of what I am looking for:
    http://feudfraud.com/en/

  7. #7
    SitePoint Member
    Join Date
    Mar 2012
    Location
    Norway
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Found something, both in php, perl and JS:
    http://ejohn.org/blog/dictionary-lookups-in-javascript/

    The JS script is what I'm looking for. So my problem is solved.

    Thanks for answers


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •