String
76 entries
addcslashes
Escapes a string C-style for the given character list (\n\t\0 become C escape sequences; ranges use the ".." syntax) — pairing with addslashes's "quote-like characters only" strategy.
addslashes / stripslashes
Escapes single quotes, double quotes, backslashes and NUL with backslashes, plus its inverse. A magic-quotes-era legacy: the manual explicitly warns it does NOT prevent SQL injection - prepared statements are the correct approach.
base64_decode
Decodes a base64-encoded string back to the original bytes.
base64_encode
Encodes data with MIME base64 (output without line breaks).
bin2hex / hex2bin
Binary string to hex string and back (byte level: every byte becomes two hex characters) — the counterpart of numeric-level dechex/hexdec (byte sequences vs formatting an integer); Python bytes.hex, Node Buffer hex and Go encoding/hex are the direct equivalents.
chr / ord
Byte-to-number conversions: chr builds a single-byte string from an unsigned byte (0-255) and ord reads the first byte — multi-byte UTF-8 characters must be built byte by byte; chr/ord in Python/Rust are codepoint-based, a fundamental difference from PHP's byte semantics.
chunk_split
Splits a string into fixed-length chunks with a separator inserted after each (default \r\n) — built for folding base64 into lines for MIME (RFC 2045); most languages have no direct counterpart and hand-write the loop.
convert_uuencode / convert_uudecode
Legacy uu encoding/decoding (length-prefixed lines, 3 bytes to 4 chars +32) — a 6bit scheme like base64 but with line structure and a ~ terminator; same encoding efficiency as base64 with more container overhead. Python's binascii matches byte for byte; other languages hand-roll it.
count_chars
Byte-level string statistics: mode 0 full table / 1 present only / 2 absent only / 3 present as string / 4 absent as string - a 256-slot byte histogram.
explode
Splits a string into an array by a delimiter.
get_html_translation_table
Returns the translation table used internally by htmlspecialchars/htmlentities (character → entity); HTML_SPECIALCHARS holds the five markup characters, HTML_ENTITIES the full set (~1500 entries under HTML5); the default flags include ENT_QUOTES since 8.1.
grapheme_strlen
Counts grapheme clusters (user-perceived characters): strlen counts bytes, mb_strlen counts code points, grapheme_strlen counts graphemes — precomposed é and decomposed é both count as 1, and the ZWJ family emoji counts as a single grapheme.
grapheme_strrev
Reverses a string by grapheme cluster (new in PHP 8.6, Intl): emoji ZWJ sequences and combining marks stay intact.
grapheme_substr
Substring by grapheme cluster: taking grapheme [1,2) of "a👨👩👧b" yields the whole family emoji, not half a code point — mb_substr with the same arguments returns only the MAN; negative offsets count from the tail, and out-of-range yields an empty string.
html_entity_decode
Converts HTML entities back to characters — the inverse of htmlentities.
htmlentities
Converts every character with an HTML entity equivalent to that entity (broader coverage than htmlspecialchars).
htmlspecialchars
Converts HTML-sensitive characters (& < > quotes) to entities — the first line of defense against XSS.
implode
Joins array elements into a single string with a delimiter.
lcfirst
Makes a string's first character lowercase.
levenshtein
Computes the Levenshtein edit distance between two strings: the minimum number of single-character insertions, deletions or substitutions.
ltrim / rtrim
Directed trimming: ltrim cuts only the left side and rtrim only the right (same default whitespace set as trim); charlist is a character SET, not a prefix/suffix string — ltrim('Hello, World!', 'He') strips the characters H and e, not the string 'He'.
mb_convert_encoding
Character encoding conversion (UTF-8/GBK/ISO-8859-1): a fixed string makes the UTF-8 -> GBK -> UTF-8 round trip lossless; compared with encode/decode, iconv, TextDecoder and Encoding across languages.
mb_detect_encoding / mb_check_encoding
Encoding detection and validation: mb_detect_encoding guesses the likeliest encoding from a candidate list (mb_detect_order: ASCII, UTF-8), while mb_check_encoding strictly validates one encoding (defaulting to the internal one); detection is probabilistic, validation gives the definite answer.
mb_internal_encoding
Sets/gets the process-wide default multibyte encoding - the implicit value behind every mb_* call that omits its encoding argument. Global mutable state: modern style prefers passing it explicitly.
mb_scrub
Replaces ill-formed byte sequences with the substitute character (default ?, settable to U+FFFD via mb_substitute_character) - the data-cleaning gate: scrub dirty input before processing.
mb_str_split / mb_strtoupper / mb_strtolower
Two-track splitting and casing: byte-cutting str_split (tears multibyte chars) vs character-cutting mb_str_split; mb_strtoupper/mb_strtolower map by Unicode properties and are locale-independent — "i" is always "I", while Turkish İ/ı needs hand mapping.
mb_strlen
Gets the character count of a string (multibyte-safe), contrasted with the byte count.
mb_strpos / mb_stripos / mb_strrpos / mb_strripos
Multibyte-safe search returning CHARACTER positions - the core contrast with strpos's byte positions: for '世界' in '你好,世界', mb gives 3 while bytes give 9.
mb_strwidth
Measures string width in terminal columns: halfwidth = 1, East Asian fullwidth = 2 (UAX #11) - the root cause of str_pad failing to align CJK text, and the fix.
mb_substr
Multibyte-safe character-level substring: contrasted with byte-level substr to demonstrate PHP's dual-track string API — most languages have naturally character-level strings with no mb_ prefix.
mb_ucfirst / mb_lcfirst
Multibyte-safe first-letter case conversion (PHP 8.4+) - mbstring's answer to ucfirst/lcfirst being ASCII-only: multibyte letters like z with caron finally convert.
nl2br
Inserts an HTML line-break tag (default <br />, XHTML style) before every newline in a string; no HTML escaping.
number_format
Formats a number with grouped thousands and a fixed number of decimal places.
printf / vprintf / vfprintf / fprintf / vsprintf
The formatted-output family: printf/fprintf write straight to a stream and return the byte count (contrast sprintf, which returns the string); the v* prefix takes an ARRAY of arguments (va_list/array instead of a variadic list).
quoted_printable_encode / quoted_printable_decode
MIME quoted-printable (RFC 2045 §6.7): non-ASCII bytes become =XX, '=' becomes =3D, lines soft-break at 75 chars (trailing '='); encode emits CRLF per the RFC; decode only expands =XX sequences.
quotemeta
Escapes the string-domain metacharacters: backslash-prefixes each of the POSIX set . \ + * ? [ ^ ] ( $ - unlike preg_quote, which escapes the regex domain; an empty string returns "" (not false) since 8.0.
similar_text
Computes string similarity: returns the number of matching characters, with an optional by-reference percentage (2×matching/(len1+len2)×100); paired with levenshtein as similarity vs edit distance.
soundex
The Soundex phonetic code: names map to a letter-plus-three-digits code so similar-sounding names collide - old but effective fuzzy name retrieval.
sprintf
Builds a formatted string from a format string and arguments.
sscanf
The input counterpart of printf(): parses fields out of a string by a format; the two-argument form returns the parsed array, while the by-reference form returns the number of fields assigned.
str_contains
Determines if a string contains a given substring and returns a boolean.
str_ends_with
Checks if a string ends with a given suffix.
str_increment / str_decrement
PHP 8.3 alphanumeric increment/decrement: rightmost digit +1 with carry (z wraps to a, 9 wraps to 0); an all-carry prepends a same-family character (zz→aaa, ZZ→AAA, 99→100); no builtin elsewhere - hand-write it.
str_ireplace
Case-insensitive replace: the case-insensitive twin of str_replace (ASCII-only folding since 8.2); array arguments map pairwise in order; &$count receives the replacement count.
str_pad
Pads a string to a given length with another string.
str_repeat
Repeats a string a given number of times.
str_replace
Replaces occurrences of a substring with another substring.
str_rot13 / str_shuffle
Classic miscellany: ROT13, the self-inverse Caesar shift (applying it twice restores the input), and string shuffling (per the PHP manual NOT cryptographically secure - global Mt19937, no injectable engine).
str_split
Splits a string into an array: single bytes by default, or fixed-length chunks; on multi-byte strings it splits BYTES, not characters (mb_str_split is the character-level counterpart).
str_starts_with
Checks if a string starts with a given prefix.
str_word_count
Counts words in a string: a word is an alphanumeric run that may contain (but not start with) ' and -; format 0 returns the count, 1 the word array, 2 an offset-to-word map — the word-level counterpart of count_chars' byte-level histogram; single-byte implementation, multibyte text needs the regex route.
strcasecmp / strncasecmp
Binary-safe case-insensitive comparison: same sign semantics as strcmp/strncmp, ASCII-only folding (locale-independent since 8.2); only the sign of the result is portable.
strcmp / strncmp
Binary-safe string comparison: returns the sign of the difference (<0/0/>0), not a bool - only the sign is portable (PHP 8.2+ no longer guarantees the strlen difference); strncmp compares only the first n characters.
strip_tags
Strips HTML and PHP tags from a string (with an optional whitelist of tags to keep).
stripos / stristr
Case-insensitive search: stripos returns the first-match position (int|false, test with ===), stristr returns the tail from the match (before_needle flips to the head); ASCII-only folding.
strlen
Returns the byte length of a string.
strpbrk
Scan for the first occurrence of ANY character from a charset: returns the tail from that position (not an index); false when nothing matches; an empty charset throws ValueError (8.0+).
strpos
Finds the position (index) of the first occurrence of a substring.
strrchr
Take from the LAST occurrence to the end (the reverse-direction mirror of strstr); before_needle (8.3+) flips to the head; false when not found.
strrev
Reverses a string.
strrpos / strripos
Finds the position of the LAST occurrence of a substring (the reverse-search member of the strpos family); strripos is its case-insensitive variant. Returns false (not -1) on miss, and a match at position 0 needs !== false.
strspn / strcspn
Character-set spans: strspn returns the length of the initial segment consisting entirely of characters in the set, strcspn the initial segment containing none of them. The purest C-lineage string functions, commonly used for input validation (strspn result equal to strlen means the whole string is legal).
strstr
Finds the first occurrence of a substring and returns the substring itself: from the match to the end by default, or the part before the match with before_needle=true; returns false on a miss.
strtok
Tokenizes a string by a delimiter set: only the first call takes the string, later calls take the delimiter only (the cursor lives in internal state); contiguous delimiters merge and leading/trailing ones are ignored — the opposite of explode, which keeps empty segments.
strtoupper
Converts all letters in a string to uppercase.
strtr
String translation: the two-string form maps characters one-to-one, the array form matches longest key first in a single pass without rescanning replaced text — the classic contrast with str_replace's order-sensitive cascading.
substr
Extracts a portion of a string.
substr_compare
Compares a window of haystack starting at the given offset against needle: equivalent to strcmp(substr(haystack, offset, length), needle) — a -1/0/+1 tri-state; length caps the window, case_insensitive ignores case; the single-function composition of the existing strcmp/substr entries.
substr_count
Counts how many times a substring occurs in a string (non-overlapping), with an optional offset/length window.
substr_replace
Replaces the portion of a string delimited by offset/length with a replacement string; omitting length replaces to the end, length 0 becomes pure insertion, a negative offset counts from the end - complementary to str_replace's global replacement.
trim
Strips whitespace from both ends of a string.
ucfirst
Converts the first letter of a string to uppercase.
ucwords
Uppercases the first character of each word. The default word boundaries are only the six whitespace characters (space/tab/CR/LF/FF/VT) - apostrophes and hyphens do not count. Python's title() and C#'s ToTitleCase follow different rules; see the comparison.
urldecode
Decodes a URL-encoded string: %XX hexadecimal escapes become characters and plus signs become spaces.
urlencode
Encodes a string per application/x-www-form-urlencoded (spaces become plus signs, other unsafe characters become %XX).
wordwrap
Wraps a string at spaces to a given width, optionally cutting words longer than that width.