本文整理汇总了PHP中diff函数的典型用法代码示例。如果您正苦于以下问题:PHP diff函数的具体用法?PHP diff怎么用?PHP diff使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了diff函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: finish
function finish($async)
{
if ($async->outs[0] !== $async->outs[2] or $async->errs[0] !== $async->errs[2] or $async->exits[0] !== $async->exits[2]) {
$output = diff($async->outs[0], $async->outs[2]);
$async->outs = $output;
$this->async_failure("Outputs dont match PHP outputs", $async);
} else {
$this->async_success($async);
}
}
示例2: htmlDiff
function htmlDiff($old, $new)
{
$diff = diff(explode(' ', $old), explode(' ', $new));
foreach ($diff as $k) {
if (is_array($k)) {
$ret .= (!empty($k['d']) ? "<del>" . implode(' ', $k['d']) . "</del> " : '') . (!empty($k['i']) ? "<ins>" . implode(' ', $k['i']) . "</ins> " : '');
} else {
$ret .= $k . ' ';
}
}
return $ret;
}
示例3: htmlDiff
function htmlDiff($old, $new, $format = array('+' => '<ins>%s</ins>', '-' => '<del>%s</del>'))
{
$diff = diff(str_split($old), str_split($new));
$ret = '';
foreach ($diff as $k) {
if (is_array($k)) {
$ret .= (!empty($k['d']) ? sprintf($format['-'], implode('', $k['d'])) : '') . (!empty($k['i']) ? sprintf($format['+'], implode('', $k['i'])) : '');
} else {
$ret .= $k . '';
}
}
return $ret;
}
示例4: do_url
public function do_url()
{
if (!isset(Vars::$get['page'])) {
throw new CommandException('パラメータが足りません。', $this);
}
$page = Page::getinstance(Vars::$get['page']);
$ret['title'] = $page->getpagename() . ' の変更点';
$smarty = $this->getSmarty();
$smarty->assign('diff', diff($page->getsource(1), $page->getsource(0)));
$ret['body'] = $smarty->fetch('diff.tpl.htm');
$ret['pagename'] = $page->getpagename();
return $ret;
}
示例5: run_main
function run_main()
{
$old_rev = (int) $_GET["old_rev"];
$new_rev = (int) $_GET["new_rev"];
$unsafe_filename = $_GET["filename"];
$sort_first = $_GET["sort"] or false;
# Sanitize the revisions: 0 < old_rev < new_rev < 5000
if (!(0 < $old_rev)) {
bad();
}
if (!($old_rev < $new_rev)) {
bad();
}
if (!($new_rev < 5000)) {
bad();
}
# Sanitize the inputs: the file should be within the results/$rev subdirectory
$relative_filename = "results/{$new_rev}/{$unsafe_filename}";
$real_filename = realpath($relative_filename);
# We find the dir by checking the fullname of this script, and stripping off the script name at the end
$real_scriptname = realpath(__FILE__);
$scriptname = "test/framework/records/diff.php";
$script_dir = str_replace($scriptname, "", $real_scriptname);
# Check that the script is within these bounds
if (strpos($real_filename, $script_dir) !== 0) {
# FALSE is a fail, but 0 isnt
bad();
}
$old_filename = realpath("results/{$old_rev}/{$unsafe_filename}");
$new_filename = realpath("results/{$new_rev}/{$unsafe_filename}");
if (!file_exists($old_filename)) {
die("No old file");
}
if (!file_exists($new_filename)) {
die("No new file");
}
$old = file_get_contents($old_filename);
if ($sort_first) {
$split = split("\n", $old);
sort($split);
$old = join("\n", $split);
}
$new = file_get_contents($new_filename);
if ($sort_first) {
$split = split("\n", $new);
sort($split);
$new = join("\n", $split);
}
echo "<pre>" . diff($old, $new) . "</pre>\n";
}
示例6: pageWritten
function pageWritten()
{
global $WIKI_TITLE, $PG_DIR, $page, $HIST_DIR, $LANG, $VAR_DIR, $PROTECTED_READ;
if ($PROTECTED_READ) {
return false;
}
$pagelink = ($_SERVER["HTTPS"] ? "https://" : "http://") . $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["SCRIPT_NAME"];
preg_match("/<\\/language>(.*)<\\/channel>/s", @file_get_contents($VAR_DIR . "rss.xml"), $matches);
$items = $matches[1];
$pos = -1;
// count items
for ($i = 0; $i < $this->max_changes - 1; $i++) {
if (!($pos = strpos($items, "</item>", $pos + 1))) {
break;
}
}
if ($pos) {
// if count is higher than $max_changes - 1, cut out the rest
$items = substr($items, 0, $pos + 7);
}
if ($opening_dir = @opendir($HIST_DIR . $page . "/")) {
// find two last revisions of page
$files = array();
while ($filename = @readdir($opening_dir)) {
if (preg_match('/\\.bak$/', $filename)) {
$files[] = $filename;
}
}
rsort($files);
$newest = diff($files[0], $files[1], $this->short_diff);
// LionWiki diff function
clearstatcache();
$timestamp = filemtime($PG_DIR . $page . ".txt");
$n_item = "\n\t<item>\n\t <title>" . h($page) . "</title>\n\t <pubDate>" . date("r", $timestamp) . "</pubDate>\n\t <link>" . h($pagelink) . "?page=" . u($page) . "</link>\n\t <description>{$newest}</description>\n\t</item>";
} else {
echo "RSS plugin: can't open history directory!";
}
$rss = str_replace('{WIKI_TITLE}', h($WIKI_TITLE), $this->template);
$rss = str_replace('{PAGE_LINK}', h($pagelink), $rss);
$rss = str_replace('{LANG}', h($LANG), $rss);
$rss = str_replace('{WIKI_DESCRIPTION}', "RSS feed from " . h($WIKI_TITLE), $rss);
$rss = str_replace('{CONTENT_RSS}', $n_item . $items, $rss);
if (!($file = @fopen($VAR_DIR . "rss.xml", "w"))) {
echo "Opening file for writing RSS file is not possible! Please create file rss.xml in your var directory and make it writable (chmod 666).";
return false;
}
fwrite($file, $rss);
fclose($file);
return false;
}
示例7: htmlDiff
/**
* Altered source code below
*/
function htmlDiff($old, $new)
{
if ($old == $new) {
return '<span style="color:#999;">— no changes —</span>';
}
$ret = '';
$diff = diff(explode(' ', $old), explode(' ', $new));
foreach ($diff as $k) {
if (is_array($k)) {
$ret .= (!empty($k['d']) ? '<span style="color:#666; text-decoration:line-through;">' . implode(' ', $k['d']) . '</span> ' : '') . (!empty($k['i']) ? '<span style="color:#f00; font-weight:bold;">' . implode(' ', $k['i']) . '</span> ' : '');
} else {
$ret .= $k . ' ';
}
}
return $ret;
}
示例8: change_page
protected function change_page($page)
{
$pagename = $page->getpagename();
if (!$page->isexist()) {
$head = "「{$pagename}」が削除されました。";
} else {
if (!$page->isexist(1)) {
$head = "「{$pagename}」が作成されました。";
} else {
$head = "「{$pagename}」が変更されました。";
}
}
$subject = '[' . SITENAME . "] {$pagename}";
$text[] = $head;
$text[] = $this->geturl($page);
$text[] = '----------------------------------------------------------------------';
$text[] = diff($page->getsource(1), $page->getsource(0), MAIL_DIFF);
sendmail($subject, join("\n", $text));
}
示例9: diff
function diff($old, $new)
{
$matrix = array();
$maxlen = 0;
foreach ($old as $oindex => $ovalue) {
$nkeys = array_keys($new, $ovalue);
foreach ($nkeys as $nindex) {
$matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ? $matrix[$oindex - 1][$nindex - 1] + 1 : 1;
if ($matrix[$oindex][$nindex] > $maxlen) {
$maxlen = $matrix[$oindex][$nindex];
$omax = $oindex + 1 - $maxlen;
$nmax = $nindex + 1 - $maxlen;
}
}
}
if ($maxlen == 0) {
return array(array('d' => $old, 'i' => $new));
}
return array_merge(diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)), array_slice($new, $nmax, $maxlen), diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen)));
}
示例10: diffsparsejson
function diffsparsejson($old, $new)
{
$diff = diff(diffstringsplit($old), diffstringsplit($new));
$adj = 0;
$out = array();
foreach ($diff as $k => $v) {
if (is_array($v)) {
if (empty($v['d']) && empty($v['i'])) {
$adj += 1;
continue;
} else {
if (empty($v['d'])) {
//insert
$out[] = array(0, $k - $adj, $v['i']);
$adj += 1;
} else {
if (empty($v['i'])) {
//delete
$out[] = array(1, $k - $adj, count($v['d']));
$adj -= count($v['d']) - 1;
} else {
//replace
$out[] = array(2, $k - $adj, count($v['d']), $v['i']);
$adj -= count($v['d']) - 1;
}
}
}
}
}
if (count($out) == 0) {
return '';
} else {
if (function_exists('json_encode')) {
return json_encode($out);
} else {
require_once "JSON.php";
$jsonser = new Services_JSON();
return $jsonser->encode($out);
}
}
}
示例11: fill
function fill($draw, $note)
{
global $summr;
global $notes;
foreach ($notes as $nom => $qnt) {
if (!isset($draw[$nom])) {
$draw[$nom] = 0;
}
}
$diff = $draw != $notes ? diff($draw) : $notes;
foreach ($diff as $nom => &$qnt) {
if ($nom == $note) {
continue;
}
while (getSumm($draw) + $nom <= $summr && $qnt > 0) {
$qnt--;
$draw[$nom]++;
}
}
return $draw;
}
示例12: history
function history($data)
{
if ($data['id']) {
$id = $data['id'];
} else {
echo 'Error';
}
$rs = getWHistory($id);
$cnt = count($rs);
if ($cnt > 1) {
if (isset($data['v1']) && $data['v1'] != 'undefined') {
$v1 = $data['v1'];
} else {
$v1 = $cnt - 2;
}
if (isset($data['v2']) && $data['v1'] != 'undefined') {
$v2 = $data['v2'];
} else {
$v2 = $cnt - 1;
}
$diffrs = diff($rs[$v1]["content"], $rs[$v2]["content"]);
$content["version"] = $cnt;
}
$contentdata = '';
if ($rs) {
for ($i = 0; $i < $cnt; $i++) {
$v = $rs[$i]["version"];
$datum = substr($rs[$i]["initdate"], 8, 2) . "." . substr($rs[$i]["initdate"], 5, 2) . "." . substr($rs[$i]["initdate"], 0, 4);
$datum .= " " . substr($rs[$i]["initdate"], 11, 2) . ":" . substr($rs[$i]["initdate"], 14, 2);
$contdata .= "<p><input type='checkbox' name='diff' id='diff{$v}' value='{$i}'>{$v} ";
$contdata .= $datum . " - " . $rs[$i]["login"] . " - " . strlen($rs[$i]["content"]) . " Byte</p>";
}
if ($cnt > 1) {
$contdata .= "Version: " . $rs[$v1]["version"] . "<hr />" . $diffrs[0] . "<br /><br />Version: " . $rs[$v2]["version"] . "<hr />" . $diffrs[1];
}
} else {
$contdata = ".:no_data:.{$cnt}";
}
echo $contdata;
}
示例13: write
/**
* ポストされたデータを元に書き込む。
*/
protected function write()
{
$source = mb_ereg_replace('\\r?\\n', "\n", Vars::$post['source']);
$seed = Vars::$post['seed'];
$notimestamp = isset(Vars::$post['notimestamp']) && Vars::$post['notimestamp'] == 'on' ? true : false;
$page = Page::getinstance(Vars::$post['pagename']);
if ($seed != md5($page->getsource())) {
$ret['title'] = '更新が衝突しました';
$smarty = $this->getSmarty();
$smarty->assign('pagename', $page->getpagename());
$smarty->assign('diff', diff($page->getsource(), $source));
$smarty->assign('form', $this->getpostform($page->getpagename(), $source, $notimestamp, md5($page->getsource())));
$ret['body'] = $smarty->fetch('conflict.tpl.htm');
$ret['pagename'] = $page->getpagename();
return $ret;
} else {
if ($source != $page->getsource()) {
//内容に変更がある場合のみ更新
$page->write($source, $notimestamp);
$this->notify(array('write', $page));
}
redirect($page);
}
}
示例14: test_file
function test_file($file)
{
echo "Testing {$file} \n";
$mpq = new MPQFile($file);
$rep = $mpq->parseReplay();
if (!$rep) {
echo "Parse error!";
return;
}
$new = $rep->jsonify();
if (file_exists($file . '.parsed')) {
$old = file_get_contents($file . '.parsed');
$diff = diff($old, $new);
if ($diff != -1) {
echo $file . ': position ' . $diff . ' old: >>' . substr($old, $diff - 5, 10) . '<< new: >>' . substr($new, $diff - 5, 10) . "<< ";
file_put_contents($file . '.new.parsed', $new);
echo "New content saved as " . $file . ".new.parsed\n";
//printDiff($old, $new);
}
} else {
file_put_contents($file . '.parsed', $new);
echo "Content saved as {$file}.parsed\n";
}
}
示例15: _
<section class="proposal_content diff">
<h2><?php
echo _("Title");
?>
</h2>
<p class="proposal proposal_title"><? diff($draft->title, $draft2->title)?></p>
<h2><?php
echo _("Content");
?>
</h2>
<p class="proposal"><? diff($draft->content, $draft2->content)?></p>
<h2><?php
echo _("Reason");
?>
</h2>
<p class="proposal"><? diff($draft->reason, $draft2->reason)?></p>
</section>
<div class="clearfix"></div>
<?
html_foot();
/**
* wrapper for PHP-FineDiff library
*
* @param string $from_text
* @param string $to_text
*/