本文整理汇总了PHP中Diff::format方法的典型用法代码示例。如果您正苦于以下问题:PHP Diff::format方法的具体用法?PHP Diff::format怎么用?PHP Diff::format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Diff
的用法示例。
在下文中一共展示了Diff::format方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Diff
function test_format()
{
$diff = new Diff(DIFF_SPACE);
$one = 'a b c d e f g';
$two = 'a c d e t t f';
$res = $diff->compare($one, $two);
$out = $diff->format($res);
$expected = array(array('', 'a'), array('-', 'b'), array('', 'c'), array('', 'd'), array('', 'e'), array('+', 't'), array('+', 't'), array('', 'f'), array('-', 'g'));
$this->assertEquals($out, $expected);
}
示例2: compare
/**
* Returns a comparison of the two specified versions of the specified item
* in the form of an associative array.
*
* @param string name of collection
* @param string name of unique id column
* @param mixed unique id of item
* @param integer unique revision id of newer version
* @param integer unique revision id of older version
* @return array hash
*
*/
function compare($collection, $key, $id, $rid1, $rid2, $diff_type = DIFF_HTML)
{
// returns diff as associative array
$rev1 = $this->getRevision($collection, $key, $id, $rid1, true);
if (!is_object($rev1)) {
$this->error = 'Revision #' . $rid1 . ' does not exist.';
return false;
}
$rev2 = $this->getRevision($collection, $key, $id, $rid2, true);
if (!is_object($rev2)) {
$this->error = 'Revision #' . $rid2 . ' does not exists.';
return false;
}
$diff = new Diff(DIFF_HTML);
$out = array();
foreach (array_keys(get_object_vars($rev1)) as $key) {
$out[$key] = $diff->format($diff->compare($rev1->{$key}, $rev2->{$key}));
}
return $out;
}