0

i want to compare two uploaded files and display the strings that are same in the two files inform of percentage but i dont know how to handle it. Any help is highly appreciated. below is my upload form.

<p>Choose files to be compared<p>
                    <hr />
                    <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">                     


                  <!--APC hidden field-->
                      <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $up_id; ?>"/>
                  <!---->

                      <input name="file" type="file" id="file" size="30"/>

                  <!--Include the iframe-->
                      <br />
                      <iframe id="upload_frame" name="upload_frame" frameborder="0" border="0" src="" scrolling="no" scrollbar="no" > </iframe>
                      <br />
                  <!---->


                  <!--APC hidden field-->
                      <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key1" value="<?php echo $up_id; ?>"/>
                  <!---->

                      <input name="file1" type="file" id="file1" size="30"/>

                  <!--Include the iframe-->
                      <br />
                      <iframe id="upload_frame" name="upload_frame" frameborder="0" border="0" src="" scrolling="no" scrollbar="no" > </iframe>
                      <br />
                  <!---->

                      <input name="Submit" type="submit" id="uploadFilesButton" style="width:250px; height:35px; background-color: #003333; color: #ffffff; border-radius: 10px;" value="PlagCheck" />
                    </form>
tshepang
  • 10,772
  • 21
  • 84
  • 127
Richmahnn
  • 87
  • 2
  • 10

1 Answers1

0

This post (How to find extra lines by comparing two files using php?) might help. So do something like:

  1. file_get_contents (put each files contents into a string)
  2. Split the string contents into arrays of words (explode(" ", $str);)
  3. Store the number of words of the file you want to get a percentage for (say File1).
  4. Remove all the words in File1's array that are in File2's array

    foreach($file2array as $word){if (in_array($word, $file1array)){unset($file1array[$word])}}

  5. Get length of File1's array at this stage.

  6. Get the percentage using the numbers from Step 3 and Step 5.

Community
  • 1
  • 1
user1135469
  • 1,000
  • 9
  • 22