Strings and Regex

Strings, Text and Regular Expressions

Form fields, URLs, headers, CSV rows and database columns all reach PHP as strings. A PHP string is a sequence of bytes with no encoding attached, and the classic functions (strlen(), substr(), strtoupper()) work on bytes: exact for ASCII, wrong for "café" or "日本". The mb_* functions count characters instead, the grapheme_* functions count what a reader sees, and the preg_* functions add the PCRE2 regular-expression engine.

Subsections