#strings 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 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.
Bash URL-Encode and URL-Decode
Encode and decode URL-safe strings entirely in bash — no python or external tool required. Useful in pure-shell deployment scripts that need to build query strings.
Java Text Blocks (Java 15+)
Multi-line string literals with proper indentation handling. Stop concatenating newlines by hand. The compiler removes the common leading whitespace automatically.
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.
TypeScript Slugify (Unicode-aware)
Turn any string into a URL-safe slug. Uses Intl normalize + diacritic stripping so "Café" becomes "cafe". No external dependency.
Go text/template — Simple Templating
Stdlib templating with `{{.Field}}` placeholders, range loops, if/else, and function pipelines. Safe alternative for non-HTML text (e.g. emails, config files).
Bash Substring + Find/Replace (parameter expansion)
Bash's ${var:offset:length} and ${var//pattern/replacement} let you do most string operations without ever spawning sed. Faster, and the syntax is portable across modern shells.
Bash Default Value for Unset Variable
Three parameter-expansion idioms for "use this if the variable is empty / unset". Replaces the verbose `if [[ -z "$VAR" ]]; then VAR=default; fi` everywhere.
Bash Uppercase / Lowercase / Title Case
Bash 4+ has built-in case conversion via parameter expansion. No need for `tr` or `awk` for most cases.
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.
Rust Format Strings (println! / write!)
Rust's format macros take an inline format string with `{}` placeholders. Named arguments, alignment, precision, debug formatting — all in the format spec.
Kotlin String Templates
Embed expressions inside double-quoted strings with `$var` or `${expr}`. No printf/format needed for 95% of cases. Raw strings (triple-quoted) skip escape processing for multiline / regex / SQL.
Python Word-Safe Truncate
Cap a string at `max_len` chars without splitting a word; append an ellipsis when truncated. Backs off to the last space if cutting mid-word would happen.
PHP Markdown to Plain Text
Strip common Markdown syntax to produce a plaintext preview suitable for excerpts, search indexes, or email subjects. Handles headings, bold/italic, links, images, code blocks, and lists.
PHP Highlight Search Term in Text
Wrap every case-insensitive occurrence of a search term in <mark> tags for quick visual highlighting in search results. Properly escapes HTML so user input cannot inject markup.
Bash Trim Whitespace from String
Strip leading and trailing whitespace without spawning sed or awk. Uses extglob + parameter expansion — much faster in tight loops than a subshell.