Summery Summery

Computes a diff between sequences of strings.

Syntax Syntax

Text_MappedDiff::__construct( array $from_lines, array $to_lines, array $mapped_from_lines, array $mapped_to_lines )

Description Description

This can be used to compute things like case-insensitve diffs, or diffs which ignore changes in white-space.

Parameters Parameters


(Required) An array of strings.


(Required) An array of strings.


(Required) This array should have the same size number of elements as $from_lines. The elements in $mapped_from_lines and $mapped_to_lines are what is actually compared when computing the diff.


(Required) This array should have the same number of elements as $to_lines.

Source Source

File: wp-includes/Text/Diff.php

    function __construct($from_lines, $to_lines,
                             $mapped_from_lines, $mapped_to_lines)
        assert(count($from_lines) == count($mapped_from_lines));
        assert(count($to_lines) == count($mapped_to_lines));

        parent::Text_Diff($mapped_from_lines, $mapped_to_lines);

        $xi = $yi = 0;
        for ($i = 0; $i < count($this->_edits); $i++) {
            $orig = &$this->_edits[$i]->orig;
            if (is_array($orig)) {
                $orig = array_slice($from_lines, $xi, count($orig));
                $xi += count($orig);

            $final = &$this->_edits[$i]->final;
            if (is_array($final)) {
                $final = array_slice($to_lines, $yi, count($final));
                $yi += count($final);



Leave a Reply