Skip to content

Latest commit

 

History

History
30 lines (20 loc) · 1.76 KB

File metadata and controls

30 lines (20 loc) · 1.76 KB

SmartString Documentation

Welcome to the SmartString docs. SmartString is a PHP string library whose output is XSS-safe by default: values HTML-encode themselves in string contexts, and chainable methods handle the everyday formatting around them.

New to SmartString? Read the first four pages in order; each builds on the one before. The rest are standalone: open whichever matches your task.

The Basics (read in order)

  1. Getting Started - Install, echo your first auto-encoded value, and the mental model: raw value for logic, encoded output for HTML.
  2. Encoding and HTML - How auto-encoding works, URL and JSON encoding, and the named methods that let real markup through: nl2br(), rawHtml(), appendHtml(), wrapHtml().
  3. Text and Formatting - Stripping HTML, truncating, regex replacement, dates, numbers, percentages, math, and custom functions with map().
  4. Conditionals and Error Checking - Fallbacks with or(), targeted replacements, true/false checks, and the or404()/orDie()/orThrow()/orRedirect() guards.

Everyday Use

  • Common Patterns - Copy-paste recipes for everyday template tasks: dates, text previews, address blocks, report tables.

Lookup

  • Method Reference - Every method in one place, grouped by what it returns.
  • Troubleshooting - Common error messages and behavior gotchas, with fixes.
  • Performance - How our automatic encoding is at least 3x faster than calling htmlspecialchars() yourself.
  • AI Reference - The complete API in one dense file, written for AI coding assistants.

← Back to main README