#php Clear
Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
PHP CSV Writer with Proper Escaping
Write rows to a CSV file using fputcsv with sensible quoting. Also writes a UTF-8 BOM so Excel opens the file with the right encoding.
PHP Truncate Text with Ellipsis (word-safe)
Cleanly truncate a string to a max length without breaking words mid-character. Adds a trailing ellipsis when truncated and never exceeds the requested length including the ellipsis.
PHP Levenshtein Similarity Percentage
Wrap PHP's built-in levenshtein() to return a similarity score from 0.0 (totally different) to 1.0 (identical). Handy for "did you mean…?" suggestions.
PHP Convert Camel Case ↔ Snake Case
Convert between camelCase and snake_case identifiers. Handy when mapping JS API responses (camelCase) into PHP database column names (snake_case) and vice versa.
PHP Normalize Phone Number to E.164
A minimal E.164 normalizer for US/CA numbers — strips formatting, prepends "+1" if missing, and validates the digit count. For full international support, reach for giggsey/libphonenumber-for-php.
PHP Send Plain Email via mail()
A thin wrapper around PHP's mail() with proper headers (From, Reply-To, Content-Type with UTF-8). For anything serious reach for PHPMailer or Symfony Mailer — this is fine for transactional one-offs.
PHP Email Address Obfuscator
Render an email address as HTML that is human-readable but resistant to naive scraping bots. Uses entity encoding and an optional Caesar-style ROT for the mailto link.
PHP CSRF Token Generate + Verify
Per-session CSRF token helpers using hash_equals for constant-time comparison. Token is regenerated on logout but persists across requests within a session.
PHP Secure Session Bootstrap
Start a session with all the security flags you should always set: HttpOnly, SameSite=Strict, Secure on HTTPS, custom name, and an idle-timeout regeneration.
PHP Number to Ordinal (1st, 2nd, 3rd)
Convert an integer to its English ordinal form ("1st", "2nd", "3rd", "11th", "22nd", "103rd"). Pure rule-based; no library needed.
PHP RGB ↔ Hex Conversion
Two-way conversion between #RRGGBB hex strings and [R, G, B] arrays. Handy when working with theme colors that come from both sources (CSS strings vs. RGB sliders).
PHP Compound Interest Calculator
Compute the future value of an investment compounded n times per year for t years. Returns both the final value and the interest earned.
PHP Haversine Distance Between Two Coordinates
Compute the great-circle distance between two latitude/longitude points using the haversine formula. Returns kilometers; multiply by 0.621 for miles. Useful for "stores near me" features.
PHP Simple File-Backed Cache
A tiny key-value cache with TTL, persisted as a serialized PHP file per key. Good enough for memoizing expensive computations on a single machine; replace with Redis when scaling out.
PHP Strip HTML Safely (whitelist tags)
Strip nearly all HTML from a string but keep a small whitelist (e.g. links, line breaks, inline formatting). Wraps strip_tags with sensible defaults and a callback to also drop event-handler attributes.
PHP Human-Readable "Time Ago"
Convert a timestamp into a short relative phrase: "just now", "5 minutes ago", "3 days ago". Falls back to an absolute date once the delta exceeds a year.
PHP Business Days Between Two Dates
Count weekdays (Mon-Fri) between two dates, excluding an optional list of holidays. Direction-aware (works even if $end < $start).
PHP Start / End of Day, Week, Month
Snap a DateTime to the start (00:00:00) or end (23:59:59) of its day, week, or month. Builds on DateTimeImmutable for value-safety.