Diff
class Diff (View source)
A class containing functions for computing diffs and formatting the output.
We can compare 2 strings or 2 files (as one string or line by line)
Constants
| UNMODIFIED |
|
| DELETED |
|
| INSERTED |
|
Methods
Returns the diff for two strings. The return value is an array, each of whose values is an array containing two values: a line (or character, if $compareCharacters is true), and one of the constants DIFF::UNMODIFIED (the line or character is in both strings), DIFF::DELETED (the line or character is only in the first string), and DIFF::INSERTED (the line or character is only in the second string). The parameters are:
Returns the diff for two files. The parameters are:
Returns a diff as a string, where unmodified lines are prefixed by ' ', deletions are prefixed by '- ', and insertions are prefixed by '+ '. The parameters are:
Returns a diff as an HTML string, where unmodified lines are contained within 'span' elements, deletions are contained within 'del' elements, and insertions are contained within 'ins' elements. The parameters are:
Returns a diff as an HTML table. The parameters are:
Details
static array<array{0: string, 1: int<0, 2>}>
compare(string $string1, string $string2, bool $compareCharacters = false)
Returns the diff for two strings. The return value is an array, each of whose values is an array containing two values: a line (or character, if $compareCharacters is true), and one of the constants DIFF::UNMODIFIED (the line or character is in both strings), DIFF::DELETED (the line or character is only in the first string), and DIFF::INSERTED (the line or character is only in the second string). The parameters are:
static array<array{0: string, 1: int<0, 2>}>
compareFiles(string $file1, string $file2, bool $compareCharacters = false)
Returns the diff for two files. The parameters are:
static string
toString(array<array{0: string, 1: int<0, 2>}> $diff, string $separator = "\n")
Returns a diff as a string, where unmodified lines are prefixed by ' ', deletions are prefixed by '- ', and insertions are prefixed by '+ '. The parameters are:
static string
toHTML(array<array{0: string, 1: int<0, 2>}> $diff, string $separator = '<br>')
Returns a diff as an HTML string, where unmodified lines are contained within 'span' elements, deletions are contained within 'del' elements, and insertions are contained within 'ins' elements. The parameters are:
static string
toTable(array<array{0: string, 1: int<0, 2>}> $diff, string $indentation = '', string $separator = '<br>')
Returns a diff as an HTML table. The parameters are: