1. String Manipulation Functions
These functions help you manipulate or transform strings.
str_replace()— Replaces all occurrences of a substring within a string.substr()— Returns a part of a string.substr_replace()— Replaces part of a string with another string.str_split()— Splits a string into an array of characters.explode()— Splits a string into an array by a delimiter.implode()— Joins elements of an array into a string.str_pad()— Pads a string to a certain length with another string.str_repeat()— Repeats a string a specified number of times.strtr()— Translates characters in a string.strtoupper()— Converts a string to uppercase.strtolower()— Converts a string to lowercase.ucwords()— Capitalizes the first letter of each word in a string.ucfirst()— Capitalizes the first letter of the string.lcfirst()— Converts the first letter of the string to lowercase.trim()— Removes whitespace from the beginning and end of a string.ltrim()— Removes whitespace or other characters from the left side of a string.rtrim()— Removes whitespace or other characters from the right side of a string.str_ireplace()— Case-insensitive version ofstr_replace().
2. String Searching and Matching
These functions allow you to search for patterns, substrings, or specific characters in a string.
strpos()— Finds the position of the first occurrence of a substring.strrpos()— Finds the position of the last occurrence of a substring.str_contains()(PHP 8.0+) — Checks if a substring exists in a string (returnstrue/false).str_starts_with()(PHP 8.0+) — Checks if a string starts with a given substring.str_ends_with()(PHP 8.0+) — Checks if a string ends with a given substring.strstr()— Finds the first occurrence of a substring and returns the rest of the string from that point.strrchr()— Finds the last occurrence of a character in a string and returns the rest of the string.preg_match()— Performs a regular expression match.preg_match_all()— Performs a global regular expression match.preg_replace()— Performs a regular expression search and replace.preg_split()— Splits a string by a regular expression pattern.
3. String Encoding and Decoding
These functions are used for encoding and decoding strings, often for use in different character sets or formats.
base64_encode()— Encodes data in base64.base64_decode()— Decodes base64-encoded data.urlencode()— Encodes a string for use in a URL.urldecode()— Decodes a URL-encoded string.rawurlencode()— Encodes a string for use in a URL, with a different encoding scheme.rawurldecode()— Decodes a raw URL-encoded string.htmlentities()— Converts special characters to HTML entities.htmlspecialchars()— Converts special characters to HTML entities, but with fewer characters.html_entity_decode()— Converts HTML entities back to their corresponding characters.utf8_encode()— Encodes a string to UTF-8.utf8_decode()— Decodes a UTF-8 string to ISO-8859-1.
4. String Length and Comparison
These functions help measure and compare string lengths, as well as compare two strings.
strlen()— Returns the length of a string.mb_strlen()— Returns the length of a string (multibyte-safe).strcmp()— Compares two strings (case-sensitive).strcasecmp()— Compares two strings (case-insensitive).strncmp()— Compares the firstncharacters of two strings (case-sensitive).strncasecmp()— Compares the firstncharacters of two strings (case-insensitive).strnatcmp()— Compares two strings using a natural order algorithm.strnatcasecmp()— Compares two strings using a natural order algorithm (case-insensitive).
5. String Positioning and Substring Extraction
These functions deal with finding or manipulating positions and substrings within a string.
strchr()— Alias ofstrstr(), finds the first occurrence of a character in a string.strrchr()— Alias ofstrrpos(), finds the last occurrence of a character in a string.strstr()— Finds the first occurrence of a substring in a string.substr()— Extracts a portion of a string.substr_count()— Counts the number of occurrences of a substring in a string.substr_compare()— Compares part of two strings.strpbrk()— Searches a string for any of a set of characters.strspn()— Returns the length of the initial segment of a string that consists entirely of characters contained in a given mask.
6. String Formatting
These functions allow you to format or manipulate strings for output.
sprintf()— Returns a formatted string.printf()— Outputs a formatted string.vsprintf()— Returns a formatted string, similar tosprintf(), but accepts an array as arguments.vprintf()— Outputs a formatted string, similar toprintf(), but accepts an array as arguments.number_format()— Formats a number with grouped thousands.chr()— Returns a character from a given ASCII code.ord()— Returns the ASCII code of a character.pack()— Packs data into a binary string.unpack()— Unpacks data from a binary string.
7. String Case Conversion
These functions are for changing the case of strings.
strtoupper()— Converts a string to uppercase.strtolower()— Converts a string to lowercase.ucfirst()— Capitalizes the first letter of a string.lcfirst()— Converts the first letter of a string to lowercase.ucwords()— Capitalizes the first letter of each word in a string.mb_convert_case()— Converts the case of a string (multibyte-safe).str_ireplace()— Case-insensitive version ofstr_replace().
8. String Trimming and Whitespace Handling
These functions are used for managing whitespace in strings.
trim()— Removes whitespace (or other characters) from the beginning and end of a string.ltrim()— Removes whitespace (or other characters) from the left side of a string.rtrim()— Removes whitespace (or other characters) from the right side of a string.str_word_count()— Counts the number of words in a string.preg_replace()— Can be used to remove unwanted whitespace patterns with regular expressions.
9. String Conversion and Parsing
These functions help in converting strings from one format to another.
strval()— Converts a variable to a string.intval()— Converts a string to an integer.floatval()— Converts a string to a float.parse_str()— Parses a query string into variables.str_getcsv()— Parses a CSV string into an array.
10. Regular Expression Functions
These functions are used for matching and manipulating strings with regular expressions.
preg_match()— Performs a regular expression match.preg_match_all()— Performs a global regular expression match.preg_replace()— Performs a regular expression search and replace.preg_split()— Splits a string by a regular expression pattern.preg_grep()— Returns an array of elements matching a regular expression.preg_filter()— Filters elements of an array using a regular expression.
11. Miscellaneous String Functions
These are some additional string-related functions that don’t fit in the other categories.
str_repeat()— Repeats a string a specified number of times.str_shuffle()— Randomly shuffles all characters in a string.str_rot13()— Encodes a string using the ROT13 cipher.soundex()— Returns the soundex key of a string (used for phonetic matching).metaphone()— Returns the metaphone key of a string (used for phonetic matching).
No hay comentarios:
Publicar un comentario