jaizendra-netizen / website-domain-cleaner
PHP CLI and library: turn the website column of a CSV into plain domains with fixed string steps (no network, no public suffix list), and list the rows that end up with the same domain.
Package info
github.com/jaizendra-netizen/website-domain-cleaner
Type:project
pkg:composer/jaizendra-netizen/website-domain-cleaner
Requires
- php: >=8.1
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-11-30 06:47:01 UTC
README
PHP command line tool and library. Give it a CSV with a row id and a website cell, as exported from a list or a CRM, and it turns each cell into a plain domain with fixed string steps. The steps run in this order: trim; an input with an @ and no :// is invalid (looks like an email address); remove a scheme (everything up to and including the first ://, whatever it is); cut at the first /, ? or #; remove user info (the text before the last @ of what is left); remove a port (a colon and digits at the end); lower-case (ASCII letters only, so give internationalised names in their xn-- form); remove one leading www.; remove one trailing dot; then check the result. The rest must have at least two labels, each 1 to 63 characters of a to z, 0 to 9 and hyphen, not starting or ending with a hyphen (xn-- labels are fine), and the last label must be at least 2 letters or an xn-- label. A host made of four dot-separated numbers from 0 to 255 is reported as an ip address, not a domain. Anything else that fails is reported as invalid with the reason. The class per row is ok (the trimmed, lower-cased input already equals the domain), cleaned, ip address or invalid. After the rows it lists every domain that appears in more than one row, with the row ids, and a summary: rows, ok, cleaned, invalid, ip, unique domains and duplicated domains (ip addresses are not counted as domains). It is pure string work: it makes no network call, does not check that a domain exists and uses no public suffix list. For that reason --keep-labels, which keeps only the last N labels, cuts two-part suffixes such as co.uk wrongly (shop.example.co.uk with 2 labels becomes co.uk). An input with an @ and no :// is rejected as an email address even when the @ sits in a path.
Part of the OneGTMLab free GTM tools. Background on the idea: PredictLeads.
Install
composer require jaizendra-netizen/website-domain-cleaner
Use
Input is a CSV with the columns row_id and website. Column names are matched without regard to case, may be in any order, and extra columns are ignored; a UTF-8 BOM and CRLF line endings are fine. An empty website cell is read as an invalid input, not as an error. Option --keep-labels N (a whole number, default 0 which keeps all labels, otherwise 2 or more, set by you) keeps only the last N labels of a domain; a domain with N labels or fewer is left as it is. A bad --keep-labels, an empty row_id, a missing column, a row with the wrong number of cells or a file with no rows exits 1 with a message; an unreadable file, an unknown option or a missing argument exits 2.
$ php bin/website-domain-cleaner sample.csv
rows read: 17, keep labels: 0 (all) (set by you)
r1: example.com -> example.com, ok
r2: https://www.Example.com/pricing?plan=1 -> example.com, cleaned
r3: http://docs.example.org:8080/a#b -> docs.example.org, cleaned
r4: user@example.com -> -, invalid: looks like an email address
r5: https://user:pass@shop.example.net/ -> shop.example.net, cleaned
r6: http://192.0.2.10/admin -> 192.0.2.10, ip address
r7: localhost -> -, invalid: needs at least two labels
r8: -bad.example.com -> -, invalid: label starts or ends with a hyphen
r9: example.com. -> example.com, cleaned
r10: www.example.com -> example.com, cleaned
r11: not a domain -> -, invalid: character " " is not allowed
r12: example..org -> -, invalid: empty label
r13: (empty) -> -, invalid: empty input
r14: Docs.Example.org -> docs.example.org, ok
r15: https://xn--bcher-kva.example/ -> xn--bcher-kva.example, cleaned
r16: example.c -> -, invalid: last label needs at least 2 letters or an xn-- label
r17: 256.1.1.1 -> -, invalid: last label needs at least 2 letters or an xn-- label
duplicated domains:
example.com: rows r1, r2, r9, r10
docs.example.org: rows r3, r14
summary: rows 17, ok 2, cleaned 6, invalid 8, ip 1, unique domains 4, duplicated domains 2
Test
php tests/run.php
Offline, no network calls, no dependencies beyond the language runtime. MIT licensed.