仅输出具有重复单词的行

I'm trying to take a list of lines, and have PHP only output the lines that contain the same word (variable) twice. It should match both singular and plural versions of the word.

Example list of lines:

This is a best website of all the websites out there

This is a great website

Here is a website I found while looking for websites

Website is a cool new word

I would put these lines into a textbox, and the script would output:

This is a best website of all the websites out there

Here is a website I found while looking for websites


No need for displaying any counts, only the raw lines that include the word twice.

I'm pretty decent at manipulating lines, but I searched everywhere for the answer to this, it seems to not exist.

For the test purpose I didn't use something like $text = $_POST['text'];, instead I used a variable to store the text, Also the class I'm using to pluralize words comes from here.

Note: I rolled back the answer to address exactly the question, the previous answer which was trying to address the comments has been moved here.

<?php    

$text = "This is a best website of all the websites out there
    This is a great website
    Here is a website I found while looking for websites
    Website is a cool new word';
// helps us pluralize all words, so we can check the duplicates 
include('class.php'); 

// loop into each line one by one
foreach(explode("
", $text) as $line)
{
        // remove special characters
        $tline = preg_replace('/[^A-Za-z0-9\-\s]/', '', $line);

        // create a list of words from current line
        $words_list = preg_split('/\s+/', strtolower($tline));

        // convert all singular words to plural
        foreach($words_list as $word)
        {
                $w[] = Inflect::pluralize($word);
        }

         // if the count of words in this line was bigger that of unique
         // words then we got some duplicates, echo this line out
        if( count($w) > count(array_unique($w)) )
                echo $line . '</br>';

        // empty the array for next line
        $w = [];
}

The output for your desired text would be:

This is a best website of all the websites out there
Here is a website I found while looking for websites

However the correctness of code really depends on how our pluralize method is working.


How it's working

First I'm looping into each line one by one using, at each iteration I'm making a list of words from that line with, then we should convert all singular words to plurals (or plural to singular it doesn't really matters), Now I've got a list of words which all of them are plural and I can easily check them to see if all of them are unique or not, if the number of words on that line is bigger than of the unique words then I can find out there are duplicates word there so I should print that line out.