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>
This post (How to find extra lines by comparing two files using php?) might help. So do something like:
file_get_contents
(put each files contents into a string)explode(" ", $str);
)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])}}
Get length of File1's array at this stage.
Get the percentage using the numbers from Step 3 and Step 5.