differingLines.php
Table of Contents
Functions
- differingLines() : int
- Counts how far apart two texts are, in lines: the lines found on one side and not on the other.
Functions
differingLines()
Counts how far apart two texts are, in lines: the lines found on one side and not on the other.
differingLines(string $a, string $b) : int
The lines are compared as a multiset, without regard to their order: a line present twice on one side and once on the other counts one, a line changed counts two (the old one and the new one), and lines that only moved count nothing. The answer is zero only when the two texts are identical, byte for byte; any other difference — lines swapped, a trailing blank, a final line break — counts one at least, so "different" is never reported as zero.
Meant as a size, not a diff: "this copy differs from the reference by 12 lines" is enough to tell a cosmetic change from a rewrite, without showing either.
Parameters
- $a : string
-
The first text, e.g. the reference.
- $b : string
-
The second text, e.g. the copy.
Tags
Return values
int —The number of lines on one side and not on the other; 1 at least when the texts differ.