Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,680
    Thanks
    28
    Thanked 4 Times in 4 Posts

    How do I finda 3-word-group in a text string?

    I am writing a little script that will improve authors writing skills by
    finding repeated phrases in the text.

    The text of a chapter will average about 10,000 words, however, I could
    reduce the size of the files if it is better to do so.

    So the idea is to search through a string and find repeats of any 3 or 4 word group.

    So if the author has repeated the phrase "then I went" 6 times in the text,
    then this would be found and highlighted.

    I am not sure where to start with this

    Maybe it is best to start by converting the string into an array of all the words?
    PHP Code:
    $word_list explode(" "$text); 
    But I still don't know how the best way to find these repeated 3 or 4 word phrases is.

    The other thing I want to provide is a list of all the words used ( maybe I will exclude
    words like and, the, a, etc) and the number of times they are used.

    Any good ideas on how I should proceed ?

    Thanks
    Last edited by jeddi; 11-04-2009 at 09:37 AM.

  • #2
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    PHP Code:
    if(preg_match_all("#\s[a-z]{3,4}\s#is"$fileContents$matches))
    {
        foreach(
    $matches[0] as $word)
        {
            echo 
    $word."<br />";
        }

    i think
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #3
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    No, that will find all alphabetic words between 3 & 4 characters in length and surrounded by white space.

  • #4
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    Quote Originally Posted by kbluhm View Post
    No, that will find all alphabetic words between 3 & 4 characters in length and surrounded by white space.
    My fault, didn't read the question correctly... will work on it some more
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 


  •  

    Posting Permissions

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