Common words found

hai.,  below is my request
 i have a textfile and paragraph.Now i need to grab the words  which are  common to both.

here string($searchthis) is  tested instead of paragraph.


please help me..
Thanks in advance!
kanaga ramuAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
What code have you tried?  This is a fairly common problem in programming class, right?
0
Ray PaseurCommented:
If you're new to PHP and want to learn the language, this article can help.  Just skip over the parts you already know from work experience or academic study.
https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html
<?php // demo/temp_ramu.php
/**
 * https://www.experts-exchange.com/questions/29012186/Common-words-found.html
 */
error_reporting(E_ALL);
echo '<pre>';

// A TEXT TO BUILD A CONCORDANCE
$text = <<<EOD
This is the list of words that should be excluded from the lookup.  Mostly these
are common words without "term of art" meanings.  You might want to add to this
list to suppress false-positive matches in your industry.  If you're a church
you might want to exclude "bible" or "worship"; if you're a car dealership you
might want to exclude "car" from the search, etc.
EOD;

// A COLLECTION OF WORDS TO SEARCH FOR IN THE TEXT
$find = <<<EOD
might
exclude
gooseball
EOD;

// BUILD THE CONCORDANCE
$text = preg_replace('/[^A-Z]/i', ' ', $text); // ALPHABET ONLY
$text = preg_replace('/\s\s+/',   ' ', $text); // NORMALIZE WHITESPACE
$text = explode(' ', $text);

$list = [];
foreach ($text as $word)
{
    $word = strtolower($word);
    if (!array_key_exists($word, $list)) $list[$word] = 0;
    $list[$word]++;
}

// FIND THE OCCURRENCES OF THE SEARCH WORDS
$find = preg_replace('/[^A-Z]/i', ' ', $find); // ALPHABET ONLY
$find = preg_replace('/\s\s+/',   ' ', $find); // NORMALIZE WHITESPACE
$find = explode(' ', $find);

foreach ($find as $word)
{
    if (array_key_exists($word, $list))
    {
        echo PHP_EOL . "$word: " . $list[$word];
    }
    else
    {
        echo PHP_EOL . "$word not found";
    }
}

Open in new window

Outputs:
might: 3
exclude: 2
gooseball not found

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
stale question
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.