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("\n", $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.