Validate emails and URLs in PHP
Use filter_var to validate email addresses and http(s) URLs, with an allow-list for schemes.
Loading snippets…
137 snippets
Use filter_var to validate email addresses and http(s) URLs, with an allow-list for schemes.
Deduplicate primitives with a Set, or objects by a key or computed value, keeping the first occurrence.
Helpers that keep key types instead of widening to string, for objects you know the shape of.
An event emitter whose event names and payloads are checked by the compiler through a generic map type.
Shorten text to a maximum length without cutting in the middle of a word or a Unicode character.
Shorten UTF-8 text with mb_ functions so accents and emoji are never cut in half.
Get the latest or highest N rows for each category using ROW_NUMBER in a subquery.
Allow bursts but cap the sustained request rate with a small thread-safe token bucket.
Measure elapsed wall-clock time of a with-block using time.perf_counter.
Sort objects by one field, then break ties with another, with ascending or descending order per field.
Keep deleted rows but still enforce unique emails among active rows using a partial unique index.
Turn text into a lowercase, hyphenated, ASCII-only slug using only the standard library.