本文整理匯總了PHP中CMbString::diff方法的典型用法代碼示例。如果您正苦於以下問題:PHP CMbString::diff方法的具體用法?PHP CMbString::diff怎麽用?PHP CMbString::diff使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CMbString
的用法示例。
在下文中一共展示了CMbString::diff方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: diff
static function diff($before, $after, $mode = "w")
{
switch ($mode) {
case 'c':
$lb = strlen($before);
$la = strlen($after);
break;
case 'w':
$before = self::splitString($before, " \t", "\r\n", $posb);
$lb = count($before);
$after = self::splitString($after, " \t", "\r\n", $posa);
$la = count($after);
break;
case 'l':
$before = self::splitString($before, "\r\n", '', $posb);
$lb = count($before);
$after = self::splitString($after, "\r\n", '', $posa);
$la = count($after);
break;
default:
return false;
}
$diff = array();
for ($b = $a = 0; $b < $lb && $a < $la;) {
for ($pb = $b; $a < $la && $pb < $lb && $after[$a] === $before[$pb]; ++$a, ++$pb) {
}
if ($pb !== $b) {
$diff[] = array('change' => '=', 'position' => $mode === 'c' ? $b : $posb[$b], 'length' => $mode === 'c' ? $pb - $b : $posb[$pb] - $posb[$b]);
$b = $pb;
}
if ($b === $lb) {
break;
}
for ($pb = $b; $pb < $lb; ++$pb) {
for ($pa = $a; $pa < $la && $after[$pa] !== $before[$pb]; ++$pa) {
}
if ($pa !== $la) {
break;
}
}
if ($pb !== $b) {
$diff[] = array('change' => '-', 'position' => $mode === 'c' ? $b : $posb[$b], 'length' => $mode === 'c' ? $pb - $b : $posb[$pb] - $posb[$b]);
$b = $pb;
}
if ($pa !== $a) {
$position = $mode === 'c' ? $a : $posa[$a];
$length = $mode === 'c' ? $pa - $a : $posa[$pa] - $posa[$a];
$change = array('change' => '+', 'position' => $position, 'length' => $length);
$diff[] = $change;
$a = $pa;
}
}
if ($a < $la) {
$position = $mode === 'c' ? $a : $posa[$a];
$length = $mode === 'c' ? $la - $a : $posa[$la] - $posa[$a];
$change = array('change' => '+', 'position' => $position, 'length' => $length);
$diff[] = $change;
}
return self::$diff = $diff;
}