title: counting Plagarism in PHP
body: <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= &quot;This is a test idea.&quot;;
  $str2= &quot;This is an experimental idea.&quot;;
  
  echo &quot;$str1&lt;br&gt;$str2&lt;br&gt;&quot;;
  
  $str1Array = explode(&quot; &quot;,$str1);
  $str2Array = explode(&quot; &quot;,$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 &quot;&lt;br&gt;$c&quot;;
              $word = $str1Array[$i];
              array_push($word_seq,$word);
          }
          else
          {
             if($lev != 0){
               
                    if($c&gt;=2)
                      $plag_count+= count($word_seq);
               $current_seq = implode(&quot; &quot;, $word_seq);
               array_push($word_seq_history,$current_seq);
               echo $current_seq;
               $c=0;
               $word_seq= array();
             }
          }
  }
  
  echo &quot;plag_count:&quot;;
  echo $plag_count;
  echo &quot;max:&quot;;
  echo $max;
  echo &quot;&lt;br&gt;&quot; ;
  echo ($plag_count/$max)*100;
  
  ?&gt;
  </code></pre>
  <p>Output:</p>
  <blockquote>
  <p>String 1: &quot;This is a test idea.&quot;</p>
  <p>String 2: &quot;This is an experimental idea.&quot;</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>