$file1 - the path to the first file
$file2 - the path to the second file
$compareCharacters - true to compare characters, and false to compare
lines; this optional parameter defaults to false
public static compareFiles ( $file1, $file2, $compareCharacters = false ) |
</pre> <table class="diff"><tr><th class="firstcolumns">F</th><th class="firstcolumns">S</th><th>Second File Output</th></tr></table> <div class="scrollingArea"> <table class="diff"> <?php if (!$Diff->isAbsPath($_GET['first'])) { $_GET['first'] = WORKSPACE . '/' . $_GET['first']; } if (!$Diff->isAbsPath($_GET['second'])) { $_GET['second'] = WORKSPACE . '/' . $_GET['second']; } $oldindex = 0; $newindex = 0; $del = 0; $ins = 0; $diff = $Diff->compareFiles($_GET['first'], $_GET['second']); foreach ($diff as $key => $line) { echo '<tr>'; if ($line[1] == 0) { $oldindex++; $newindex++; echo '<td class="linenumber firstcolumns">' . $oldindex . '</td><td class="linenumber firstcolumns">' . $newindex . '</td>'; echo '<td class="diffUnmodified"><span>' . htmlspecialchars($line[0]) . '</span></td>'; } else { if ($line[1] == -1) { $oldindex++; $del++; echo '<td class="linenumber firstcolumns">' . $oldindex . '</td><td class="linenumber firstcolumns"></td>'; echo '<td class="diffDeleted"><span>' . htmlspecialchars($line[0]) . '</span></td>'; } else { if ($line[1] == 1) {
} else { for ($i = 0; $i < 5; $i++) { $final[$i] = ""; exec("timeout 0.1s sh run.sh " . $b . ".c.out " . $testcase_i[$i], $output, $status); foreach ($output as $line) { $final[$i] .= "{$line}\n"; } $output = ""; if ($status == 124) { $response["testcase" . $i] = "Failed"; $response["error"] = true; $response["message"] = "Timed Out"; } else { $fileName = $b . "Output.txt"; file_put_contents($fileName, $final[$i]); $diff = Diff::compareFiles($fileName, $testcase_o[$i]); if ($diff[0][1] == 0) { if ($response["error"] == true) { $response["error"] = true; } else { $response["error"] = false; } $response["testcase" . $i] = "Passed"; $response["message"] = "Success"; } else { $response["testcase" . $i] = "Failed"; $response["error"] = true; $response["message"] = "Failure"; } } }
<?php require_once "diff_class.php"; $microstart = explode(' ', microtime()); $start_time = $microstart[0] + $microstart[1]; echo Diff::toString(Diff::compareFiles('old_char_346.xml', 'char_346.xml', false)); $microstop = explode(' ', microtime()); $stop_time = $microstop[0] + $microstop[1]; echo "Expired time: " . ($stop_time - $start_time) . "<br>"; echo "Memory load: " . memory_get_usage() . " bytes";
<?php require_once 'class.Diff.php'; $target_dir = __DIR__ . "/uploads/"; $diff = Diff::compareFiles('old.txt', 'new.txt'); $newfile = fopen($target_dir . "changes.txt", "w") or die("Unable to open file!"); foreach ($diff as $line) { if ($line[1] === 2) { $array = explode("\t", $line[0]); fwrite($newfile, $array[2] . "\n"); } } fclose($newfile); echo "done";
<?php $email = $website_url = $handle = fopen("/opt/lampp/htdocs/{$email}/{$website_url}/change.txt", "r"); if ($handle) { while (($line = fgets($handle)) !== false) { $pieces = explode(" ", $line); $variable1 = $pieces[0]; if ($variable1 == "Files") { $variable2 = $pieces[1]; $variable3 = $pieces[3]; ob_start(); require_once '/opt/lampp/htdocs/project/class.Diff2.php'; $d = Diff::toTable(Diff::compareFiles("{$variable2}", "{$variable3}")); echo "<iframe src='http://localhost/left.html' width='49%' height='100%'></iframe>"; echo "<iframe src='http://localhost/right.html' width='49%' height='100%'></iframe>"; require_once '/opt/lampp/htdocs/project/class.Diff.php'; $d = Diff1::toTable(Diff1::compareFiles("{$variable2}", "{$variable3}")); echo $d; $content = ob_get_contents(); ob_end_clean(); $variable2 = str_replace("/", ".", $variable2); $variable3 = str_replace("/", ".", $variable3); $search = ".opt.lampp.htdocs.{$email}.{$website_url}."; $variable2 = str_replace($search, '', $variable2); $variable3 = str_replace($search, '', $variable3); file_put_contents("/opt/lampp/htdocs/{$email}/{$website_url}/diff/{$variable2}.{$variable3}.html", $content); } else { $variable1 = $pieces[2]; $variable2 = $pieces[3]; $variable1 = str_replace(":", "/", $variable1); $output1 = "cp {$variable1}{$variable2} /opt/lampp/htdocs/{$email}/{$website_url}/diff/";
echo $originalCodeFile . PHP_EOL . 'File do not exist' . PHP_EOL; echo 'program could not check the code whether correct or not' . PHP_EOL; } echo "-----------------Diff show me the differ : ------------------\n"; $originalOPTB_WOCFile = ORIGIN_FILE_PATH . $path_parts['filename'] . '-objectcode.txt'; if (file_exists($originalOPTB_WOCFile)) { $diffOPTB_WOC = Diff::compareFiles($originalOPTB_WOCFile, $OPTB_WOCtxtFile); echo Diff::toString($diffOPTB_WOC); create_file(RESULT_PATH . $OUTPUT_LOG_PREFIX . "diff-OPTB_WOC.html", Diff::toHTML($diffOPTB_WOC)); echo "\n"; } else { echo $originalOPTB_WOCFile . "\n" . 'do not exist' . "\n"; } $orignalObjectPFile = ORIGIN_FILE_PATH . $path_parts['filename'] . '-objectprogram.txt'; if (file_exists($orignalObjectPFile)) { $diffObjectP = Diff::compareFiles($orignalObjectPFile, $obectProgramTxtFile); echo Diff::toString($diffObjectP); create_file(RESULT_PATH . $OUTPUT_LOG_PREFIX . "diff-ObjectProgram.html", Diff::toHTML($diffObjectP)); echo "\n"; } else { echo $orignalObjectPFile . "\n" . 'do not exist' . "\n"; } echo "-------------------------Diff end ----------------------------\n"; compare_array_in_html_js(RESULT_PATH . $OUTPUT_LOG_PREFIX . "compare_html_js.html", $OPTB_WOC, $orignalCode, "Compare Array", false); } ## end ## print out OPTB } } } } }