Пример #1
0
    # $f3 = file("path to file"); 
     
    $f1 = implode( "\n", $f1_arr );  
    $f2 = implode( "\n", $f2_arr );  

    print "<pre>"; 
    print "Input-Data: <xmp>"; 
    print_r( $f1_arr ); 
    print_r( $f2_arr ); 
    print "</xmp>"; 

    print "<hr />new, old <br />";  
    print PHPDiff( $f1, $f2 ); 

    print "<hr />old, new <br />";  
    print PHPDiff( $f2, $f1 ); 


    #comparing with array_diff() 

    print "<hr>Compared: array_diff( \$f1_arr, \$f2_arr );<br> "; 
    print "<xmp>"; 
    print_r ( array_diff( $f1_arr, $f2_arr ) ); 
    print "</xmp>"; 
     
    print "<hr>Compared: array_diff( \$f2_arr, \$f1_arr );<br> "; 
    print "<xmp>"; 
    print_r ( array_diff( $f2_arr, $f1_arr ) ); 
    print "</xmp>"; 
    print "</pre>"; 
Пример #2
0
    error("Invalid course id!!!");
}
require_login($course->id);
if (!confirm_sesskey()) {
    error("Session key error!!!");
}
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('format/cms:editpage', $context);
print_header();
if ($selected = get_record("cmspages_history", "id", $versionid)) {
    $preversion = floatval($selected->version) - 0.1;
    if ($preversion == 1) {
        $preversion = '1.0';
    }
    if ($previous = get_record("cmspages_history", "pageid", $selected->pageid, "version", "{$preversion}")) {
        $diff = PHPDiff($previous->content, $selected->content);
    }
}
$strversion = get_string('version');
if (!empty($diff)) {
    error_reporting(0);
    $oldfile = explode("\n", cms_format_html($previous->content, false));
    $newfile = explode("\n", cms_format_html($selected->content, false));
    $difflines = explode("\n", $diff);
    echo '<table border="1" cellpadding="4" width="100%">';
    echo '<tr><td width="50%">' . $strversion . ': ' . $preversion . '</td>';
    echo '<td width="50%">' . $strversion . ': ' . $selected->version . '</td></tr>';
    foreach ($difflines as $line) {
        preg_match("/^([0-9\\,]+)([a|c|d])([0-9\\,]+)\$/i", $line, $match);
        $out = $match[1];
        $status = $match[2];
Пример #3
0
    // cache result in memory
    if (!isset($dir[$path]) || $nocache) {
        $dir[$path] = scandir($path);
    }
    foreach ($dir[$path] as $i => $entry) {
        if ($entry != '.' && $entry != '..' && fnmatch($mask, $entry)) {
            $sdir[] = $entry;
        }
    }
    return $sdir;
}
?>

<?php 
$post_file = fopen('compress.zlib://php://input', 'rb');
$game_id = $_SERVER['HTTP_GAME_ID'];
mkdir($game_id);
$client_hash = md5($_SERVER['REMOTE_ADDR']);
$post_data = '';
while (!feof($post_file)) {
    $post_data .= fread($post_file, 8192);
}
if ($_SERVER['HTTP_DIFF']) {
    foreach (sdir($game_id, '*.' . $_SERVER['HTTP_CHANNEL'] . '.log') as $f) {
        $hash = substr($f, 0, strpos($f, '.'));
        $diff = PHPDiff(file_get_contents($game_id . '/' . $f), $post_data);
        file_put_contents($game_id . '/' . $hash . '.' . $client_hash . '.' . $_SERVER['HTTP_CHANNEL'] . '.diff', $diff);
    }
}
file_put_contents($game_id . '/' . $client_hash . '.' . $_SERVER['HTTP_CHANNEL'] . '.log', $post_data);
fclose($post_file);
Пример #4
0
<?php
			if($ld == $ddv){
				$lnr = 0;
				foreach ( explode("\n",$rdvc[1]) as $cl ){
					$lnr++;
					echo Shoconf($cl,$smo,$lnr);
				}
				echo "</div></td></tr></table><p>";
			}else{
				$query	= GenQuery('configs','s','configs.*','','',array('device'),array('='),array($ddv),'LEFT JOIN devices USING (device)');
				$res	= DbQuery($query,$link);
				$cfgok	= DbNumRows($res);
				if ($cfgok == 1) {
					$ddvc = DbFetchRow($res);
					DbFreeResult($res);
					echo PHPDiff( Opdiff($rdvc[1],$cm), Opdiff($ddvc[1],$cm),($cm == 'v')?1:0 );		
					echo "</div></td></tr></table><p>";
				}else{
					echo "<h4>$ddv: $cfgok $vallbl</h4>";
				}
			}
		}
	}else{
		$ina	='config';
		$opa	= '~';
		if($shl == 'i'){
			$opa	= '!~';
		}elseif($shl == 'c'){
			$ina	='changes';
		}elseif($shl == 't'){
			$ina	='type';
Пример #5
0
function compare_text()
{
    $successfully_compared_text = "false";
    $msg = '';
    $highlight_diff_html = '';
    $daisydiff_html = '';
    $percent_results_html = '';
    if (isset($_POST['old_text']) && $_POST['old_text'] != '' || isset($_POST['new_text']) && $_POST['new_text'] != '') {
        $old_text = $_POST['old_text'];
        $new_text = $_POST['new_text'];
        $levenshtein_distance = levenshtein($old_text, $new_text);
        //levenshtein
        $levenshtein_percentage = asimilar($old_text, $new_text);
        //levenshtein percentage
        similar_text($old_text, $new_text, $similar_text_percentage);
        //returns similar text percentage
        $trimmedstr1 = trim($old_text);
        $trimmedstr2 = trim($new_text);
        $f1_arr = explode(" ", $trimmedstr1);
        $f2_arr = explode(" ", $trimmedstr2);
        $f1 = implode("\n", $f1_arr);
        $f2 = implode("\n", $f2_arr);
        $array_val = PHPDiff($f1, $f2);
        $f2_string = explode("\n", $f2);
        $array_val_arr = explode("\n", $array_val);
        array_pop($array_val_arr);
        $highlightarr = array();
        foreach ($array_val_arr as &$value) {
            $range = "";
            $range = strstr($value, ',');
            if ($range) {
                $rangefrom = substr($value, 0, strpos($value, ','));
                $rangeto = substr($value, strpos($value, ',') + 1);
                for ($i = $rangefrom; $i <= $rangeto; $i++) {
                    $highlightarr[] = $i - 1;
                }
            } else {
                $highlightarr[] = $value - 1;
            }
        }
        $highlight_diff_html = '<p><h2>Simple text comparison results</h2></p>';
        $highlight_diff_html .= "<table width='100%' border='1'><tr><td width='10%'>Orginal:</td><td>" . $old_text . "</td></tr>";
        $highlight_diff_html .= "<tr><td width='10%'>Change:</td><td>";
        for ($i = 0; $i < sizeof($f2_string); $i++) {
            foreach ($highlightarr as $value) {
                if ($i == $value) {
                    $flg = 1;
                }
            }
            if ($flg == 1) {
                $flg = 0;
                $highlight_diff_html .= "<font color='#00FF00'>" . $f2_string[$i] . "</font>&nbsp;";
            } else {
                $highlight_diff_html .= $f2_string[$i] . "&nbsp;";
            }
        }
        $highlight_diff_html .= "</td></tr></table>";
        $daisydiff_html = '<p><h2>Daisydiff comparison results</h2></p>';
        $daisydiff_html .= daisydiff_text($old_text, $new_text);
        $percent_results_html = '<p><h2>Percentage of similar text</h2></p>';
        $percent_results_html .= "The levenshtein distance for the strings is " . $levenshtein_distance . " <br/>";
        $percent_results_html .= "Using levenshtein distance, the strings are " . $levenshtein_percentage . " percent similar <br/>";
        $percent_results_html .= "Using similar text, the strings are " . $similar_text_percentage . " percent similar <br/>";
        $successfully_compared_text = "true";
    } else {
        $msg = 'No text passed to compare!';
    }
    $returnJSON['levenshtein_distance'] = $levenshtein_percentage;
    $returnJSON['levenshtein_percentage'] = $levenshtein_percentage;
    $returnJSON['similar_text_percentage'] = $similar_text_percentage;
    $returnJSON['daisydiff_html'] = $daisydiff_html;
    $returnJSON['highlight_diff_html'] = $highlight_diff_html;
    $returnJSON['percent_results_html'] = $percent_results_html;
    $returnJSON['successfully_compared_text'] = $successfully_compared_text;
    $returnJSON['msg'] = $msg;
    echo json_encode($returnJSON);
}
Пример #6
0
<a href=?shc=<?php 
echo $ud;
?>
><img src="img/16/cfg2.png" align="right" title="Show Config"></a><div class="code">
<?
			if($ld == $ddv){
				Shoconf($rdvc[1],0,1);
				echo "</div></td></tr></table><p>";
			}else{
				$query	= GenQuery('configs','s','*','','',array('device'),array('='),array($ddv));
				$res	= @DbQuery($query,$link);
				$cfgok	= @DbNumRows($res);
				if ($cfgok == 1) {
					$ddvc = @DbFetchRow($res);
					@DbFreeResult($res);
					echo PHPDiff( Opdiff($rdvc[1],$cm), Opdiff($ddvc[1],$cm) );		
					echo "</div></td></tr></table><p>";
				}else{
					echo "<h4>$ddv $n1rmsg ($cfgok)</h4>";
				}
			}
		}
	}else{
		$target	='config';
		$opa	= 'regexp';
		if($shl == 'i'){
			$opa	= 'not regexp';
		}elseif($shl == 'c'){
			$target	='changes';
		}elseif($shl == 'd'){
			$opa	= '=';
Пример #7
0
            $c_output = $t_output;
        }
        $c_result = trim($c_result) . "\n";
        $c_output = trim($c_output) . "\n";
        $proc_time = $end_time - $start_time;
        $all_times[] = $proc_time;
        $total_time += $proc_time;
        if ($c_result == $c_output) {
            printf("OK %8d ms\n", $proc_time);
            $tests_passed++;
        } else {
            printf("FAILED %4d ms\n", $proc_time);
            $tests_failed++;
            if ($show_diff) {
                echo "~~~\n";
                echo PHPDiff($c_result, $c_output, true);
                echo "~~~\n\n";
            }
        }
    }
}
echo "\n";
//echo "$tests_passed passed ";
sort($all_times);
$average_time = $total_time / ($tests_passed + $tests_failed);
$min_time = min($all_times);
$max_time = max($all_times);
$quarter1_index = count($all_times) / 4;
$quarter2_index = count($all_times) / 2;
$quarter3_index = count($all_times) * 3 / 4;
$quarter1_time = ($all_times[floor($quarter1_index)] + $all_times[ceil($quarter1_index)]) / 2;