PHP Classes

File: Example.php

Recommend this page to a friend!
  Classes of Er. Rochak Chauhan   Compare Files   Example.php   Download  
File: Example.php
Role: Example script
Content type: text/plain
Description: Example Script
Class: Compare Files
Compare two text files and show different lines
Author: By
Last change:
Date: 19 years ago
Size: 2,544 bytes


Class file image Download
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
        <title> Test for Rochak Chauhan's CompareFiles Class </title>
        <script language="JavaScript" type="text/javascript">
            function onSubmit() {


    <font face="verdana" size="4" color="green" >Please Select the two files, which are to be compared.</font>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
    <table border="0" width="100%" cellspacing="0" cellpadding="0" style="border-top: medium solid #000000;border-right: medium solid #000000;border-left: medium solid #000000;border-bottom: medium solid #000000">
        <tr >
            <td width="50%" align="center" bgcolor="#ccddff">
                <font face="verdana" size="3" ><b>Select the main file: </b></font>
                <input type="file" name="mainFile"/>
            <td width="50%" align="center" bgcolor="#ffccdd">
                <font face="verdana" size="3" ><B>Select the file to be compared: </b></font>
                <input type="file" name="fileToCompare"/>
            <td colspan="2" align="center">
                    <input type="submit" value="Start Comparison" name="submitButton" onclick="return onSubmit()"/>
            <td colspan='2'>
                <br />

if( isset($_POST['submitButton'])) {
$compareFiles = new ClassToCompareFiles;

// File paths of the two files
$file1 = $_FILES['mainFile']['tmp_name'];
$file2 = $_FILES['fileToCompare']['tmp_name'];

$file1Contents = file($file1);
$file2Contents = file($file2);

$compareFiles->compareFiles($file1, $file2);
<center><font face="verdana" size="6" ><B> Comparison Result </b></font> </center> <br />
echo "<center><font face='verdana' size='3' color='green'><b>Number of Similar line(s): ". $compareFiles->cnt1."</font><br />";
"<BR /><font face='verdana' size='3' color='red'>Number of Different line(s): ". $compareFiles->cnt2."</font></center></b><br />";
<table border="1" style="width:100%;height:400px" cellspacing="0" cellpadding="0">
            <td bgcolor="#ccddff" style="width:50%" >
                <iframe src="file1.html" width="100%" height="400" frameborder='0' ></iframe>
            <td bgcolor="#ffccdd" style="width:50%" >
                <iframe src="file2.html" width="100%" height="400" frameborder='0' ></iframe>