String

76 entries

addcslashes Function 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 Function 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 Function Decodes a base64-encoded string back to the original bytes. base64_encode Function Encodes data with MIME base64 (output without line breaks). bin2hex / hex2bin Function 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 Function 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 Function 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 Function 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 Function 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 Function Splits a string into an array by a delimiter. get_html_translation_table Function 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 Function 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 Function Reverses a string by grapheme cluster (new in PHP 8.6, Intl): emoji ZWJ sequences and combining marks stay intact. grapheme_substr Function 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 Function Converts HTML entities back to characters — the inverse of htmlentities. htmlentities Function Converts every character with an HTML entity equivalent to that entity (broader coverage than htmlspecialchars). htmlspecialchars Function Converts HTML-sensitive characters (& < > quotes) to entities — the first line of defense against XSS. implode Function Joins array elements into a single string with a delimiter. lcfirst Function Makes a string's first character lowercase. levenshtein Function Computes the Levenshtein edit distance between two strings: the minimum number of single-character insertions, deletions or substitutions. ltrim / rtrim Function 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 Function 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 Function 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 Function 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 Function 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 Function 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 Function Gets the character count of a string (multibyte-safe), contrasted with the byte count. mb_strpos / mb_stripos / mb_strrpos / mb_strripos Function 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 Function 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 Function 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 Function 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 Function Inserts an HTML line-break tag (default <br />, XHTML style) before every newline in a string; no HTML escaping. number_format Function Formats a number with grouped thousands and a fixed number of decimal places. printf / vprintf / vfprintf / fprintf / vsprintf Function 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 Function 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 Function 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 Function 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 Function 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 Function Builds a formatted string from a format string and arguments. sscanf Function 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 Function Determines if a string contains a given substring and returns a boolean. str_ends_with Function Checks if a string ends with a given suffix. str_increment / str_decrement Function 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 Function 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 Function Pads a string to a given length with another string. str_repeat Function Repeats a string a given number of times. str_replace Function Replaces occurrences of a substring with another substring. str_rot13 / str_shuffle Function 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 Function 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 Function Checks if a string starts with a given prefix. str_word_count Function 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 Function 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 Function 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 Function Strips HTML and PHP tags from a string (with an optional whitelist of tags to keep). stripos / stristr Function 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 Function Returns the byte length of a string. strpbrk Function 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 Function Finds the position (index) of the first occurrence of a substring. strrchr Function 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 Function Reverses a string. strrpos / strripos Function 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 Function 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 Function 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 Function 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 Function Converts all letters in a string to uppercase. strtr Function 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 Function Extracts a portion of a string. substr_compare Function 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 Function Counts how many times a substring occurs in a string (non-overlapping), with an optional offset/length window. substr_replace Function 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 Function Strips whitespace from both ends of a string. ucfirst Function Converts the first letter of a string to uppercase. ucwords Function 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 Function Decodes a URL-encoded string: %XX hexadecimal escapes become characters and plus signs become spaces. urlencode Function Encodes a string per application/x-www-form-urlencoded (spaces become plus signs, other unsafe characters become %XX). wordwrap Function Wraps a string at spaces to a given width, optionally cutting words longer than that width.