Stupid PHP Question RESOLVED:CLOSED Thanks

5 replies
Example: I am trying to find all words in a text file ending in "ing"

For the life of me, I cannot figure out the pattern for preg_match_all

Please help!!

Thanks in advance,

Ted
#php #question #stupid
  • Profile picture of the author Levada
    found this:

    int preg_match_all ( string $pattern , string $subject , array &$matches [, int $flags [, int $offset ]] )
    Searches subject for all matches to the regular expression given in pattern and puts them in matches in the order specified by flags .

    After the first match is found, the subsequent searches are continued on from end of the last match.

    hope it helps!

    Levada Pendry
    {{ DiscussionBoard.errors[427575].message }}
  • Profile picture of the author aGor
    I don't know for sure, but try with
    preg_match("/ing /",$string);
    {{ DiscussionBoard.errors[427605].message }}
    • Profile picture of the author Bruce Hearder
      The search you are doing sounds a lot like the work thats been done of stemming :

      Example, thenstem of the word connections is connect, etc

      Do a quick Google search for Porter Stemming and I'm sure you will find a couple of 1/2 decent PHP classes that will do pretty much what you want..

      Also, check out phpclasses.org always a good place to go for code snippets..

      Take care

      Bruce
      {{ DiscussionBoard.errors[429072].message }}
      • Profile picture of the author ltdraper
        This code:

        $text = <<<END
        The raining in Spain is always remaining on the plain.
        END;

        preg_match_all( '/\b([a-zA-Z].*?)ing\b/', $text, $m);

        produces array m where:

        array(2) {
        0 => array(2) {
        0 => string(7) raining
        1 => string(9) remaining
        }
        1 => array(2) {
        0 => string(4) rain
        1 => string(6) remain
        }
        }

        Which is what I think you asked for.

        And you might have gotten a better response over in the programming topic.
        Signature

        Nothing to see here, move along...

        {{ DiscussionBoard.errors[429127].message }}

Trending Topics