DiffMatchPatch\DiffToolkit::linesToChars PHP Method

linesToChars() public method

Split two texts into an array of strings. Reduce the texts to a string of hashes where each Unicode character represents one line.
public linesToChars ( string $text1, string $text2 ) : array
$text1 string First string.
$text2 string Second string.
return array Three element array, containing the encoded text1, the encoded text2 and the array of unique strings. The zeroth element of the array of unique strings is intentionally blank.
    public function linesToChars($text1, $text2)
    {
        // e.g. $lineArray[4] == "Hello\n"
        $lineArray = array();
        // e.g. $lineHash["Hello\n"] == 4
        $lineHash = array();
        // "\x00" is a valid character, but various debuggers don't like it.
        // So we'll insert a junk entry to avoid generating a null character.
        $lineArray[] = '';
        $chars1 = $this->linesToCharsMunge($text1, $lineArray, $lineHash);
        $chars2 = $this->linesToCharsMunge($text2, $lineArray, $lineHash);
        return array($chars1, $chars2, $lineArray);
    }