Most efficient way to find matching words from paragraph

I have a Paragraph that I have to parse for different keywords. For example, Paragraph:

“I want to make a change in the world. Want to make it a better place to live. Peace, Love and Harmony. It is all life is all about. We can make our world a good place to live”

And my keywords are

“world”, “earth”, “place”

I should report whenever I have a match and how many times.

Output should be:

“world” 2 times and “place” 1 time

Currently, I am just converting Paragraph strings to array of characters and then matching each keyword with all of the array contents.
Which is wasting my resources.
Please guide me for an efficient way.( I am using PHP)

Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.