Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
There are 2 textareas that will take input from users. First, it will check the common words that appears more than one in both textareas and count the frequency of words occurences. Second, checks whether one of the texts could have been derived from the other by replacing all of the words, but keeping the same number of words per line, multiple space characters, tab characters, punctuation marks and etc. Third, count the percentage of words similarity.
I am still trying hard for this. I'm still a beginner, I have been trying the first problem but it didnt work properly. Here is my code. Please help!!Code: Select all
<?
$input1 = ""; if (isset($_POST["t1"])) {$input1 = $_POST["t1"];}
$input2 = ""; if (isset($_POST["t2"])) {$input2 = $_POST["t2"];}
$submit = ""; if (isset($_POST["submit"])) {$submit = $_POST["submit"];}
if ($submit!=""){
//trim the whitespace from both sides and compress the whitespace in the middle of the string
$input1=ereg_replace('[[]]+','',trim($input1));
$input2=ereg_replace('[[]]+','',trim($input2));
//break string into an array
$words= (explode(' ',$input1));
$words2= (explode(' ',$input2));
//iterate over the array and count the occurences
foreach ($words as $w)
{
$wordStats[$w]++;
}
foreach ($words2 as $w2)
{
$wordStats2[$w2]++;
}
//print all duplicate words
foreach ($wordStats as $a=>$b)
{
if ($b >=2)
{
echo $a;
}
}
foreach ($wordStats2 as $c=>$d)
{
if ($d >= 2)
{
echo $c;
}
}
$numwords = str_word_count($input1);
$numwords2 = str_word_count($input2);
//count percentage
similar_text($input1,$input2,$percent);feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]