https://github.com/corncodecreators/line-dumper
Show and compare strings - line by line.
https://github.com/corncodecreators/line-dumper
compare line-by-line string
Last synced: 3 months ago
JSON representation
Show and compare strings - line by line.
- Host: GitHub
- URL: https://github.com/corncodecreators/line-dumper
- Owner: CornCodeCreators
- Created: 2024-08-04T15:02:10.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-08-26T08:48:58.000Z (10 months ago)
- Last Synced: 2025-09-28T19:23:42.343Z (9 months ago)
- Topics: compare, line-by-line, string
- Language: PHP
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# LineDumper
> Show and compare strings - line by line.
## Summary
This PHP class, `LineDumper`, provides a utility for comparing two strings line by line and highlights the differences between them.
- If the strings are identical, it simply returns "Strings are equal!".
- If they differ, it compares them line by line, indicating mismatches with color-coded output using ANSI escape codes.
## Details
- Namespace and Class Definition: The class is defined under the CornCodeCreators namespace.
- compareLines Method:
- Input: It takes two strings, $expectedString and $actualString, which represent the expected output and the actual output.
- Output: It returns a string containing either a confirmation that the strings are equal or a line-by-line comparison highlighting differences.
- String Splitting: The strings are split into arrays of lines using explode("\n", $string).
- Line Number Width: The line numbers are padded to a width of 3 characters.
- Comparison: Each line from the expected string is compared to the corresponding line in the actual string:
- If the lines match, it outputs them with a simple "ok" status.
- If they don't match, it outputs the expected line in yellow (to-be) and the actual line in red (as-is).
## Example
**Input**
```php
$expected = "This is a line.\nAnother line.";
$actual = "This is a line.\nAnother different line.";
$comparedLines = LineDumper::compareLines($expected, $actual);
echo($comparedLines);
```
**Output**
```shell
Line 1| ok| This is a line.
Line 2|to-be| Another line.
Line 2|as-is| Another different line.
```
## Installation
```shell
$ composer require corncodecreators/line-dumper
```