本文整理汇总了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;
}