counting Plagarism in PHP
<p>Forgive me if this isn't a programming oriented question.</p>

<p>Lets say we have two sentences</p>

<blockquote>
  <p>[1]=This is a test idea<br>
  [2]=This is an experimental idea</p>
</blockquote>

<p>If I jumble up <code>[1]</code></p>

<blockquote>
  <p>[1]= a This idea test is</p>
</blockquote>

<p>Would this count as plagiarism? What sort of logic do I have to apply to detect plagiarism.
I'm not making a complexed plagiarism service, but a rather simple one what can catch obvious plagiarism.</p>

<p>My logic is somewhat like this</p>

<pre><code>&lt;?php

$str1= "This is a test idea.";
$str2= "This is an experimental idea.";

echo "$str1&lt;br&gt;$str2&lt;br&gt;";

$str1Array = explode(" ",$str1);
$str2Array = explode(" ",$str2);

if(count($str1Array) &gt; count($str2Array))
$max=count($str1Array);
else
$max=count($str2Array);

$word_seq = array();
$word_seq_history = array();
$c=0;
$plag_count=0;

for ($i = 0; $i &lt; $max; $i++) {
        $lev = levenshtein($str1Array[$i], $str2Array[$i]);    // check for an exact match

        if ($lev == 0) {
            $c+=1;//  (exact match)
            //echo "&lt;br&gt;$c";
            $word = $str1Array[$i];
            array_push($word_seq,$word);
        }
        else
        {
           if($lev != 0){

                  if($c&gt;=2)
                    $plag_count+= count($word_seq);
             $current_seq = implode(" ", $word_seq);
             array_push($word_seq_history,$current_seq);
             echo $current_seq;
             $c=0;
             $word_seq= array();
           }
        }
}

echo "plag_count:";
echo $plag_count;
echo "max:";
echo $max;
echo "&lt;br&gt;" ;
echo ($plag_count/$max)*100;

?&gt;
</code></pre>

<p>Output:</p>

<blockquote>
  <p>String 1: "This is a test idea."</p>
  
  <p>String 2: "This is an experimental idea."</p>
  
  <p>Words_Same:2 max:5</p>
  
  <p>Plagiarism: 40%</p>
</blockquote>

<p>Do I need to change it or is it fine the way it is?</p>
