Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP 5 String Functions

PHP 5 String Functions


PHP 5 String Functions

PHP String functions are part of the PHP core. These functions can be used without installation.


function Description
addcslashes() Returns a string with backslashes added before specified characters.
addslashes() Returns a string with backslashes added before predefined characters.
bin2hex() Converts a string of ASCII characters to hexadecimal values.
chop() Removes whitespace or other characters from the right side of a string.
chr() Returns a character from a specified ASCII value.
chunk_split() Splits a string into a series of smaller parts.
convert_cyr_string() Converts a string from one Cyrillic character set to another.
convert_uudecode() Decodes a uuencode-encoded string.
convert_uuencode() Encodes a string using the uuencode algorithm.
count_chars() Returns information about the characters used in a string.
crc32() Calculates the 32-bit CRC (cyclic redundancy check) of a string.
crypt() One-way string encryption (hashing).
echo() Outputs one or more strings.
explode() Splits a string into an array.
fprintf() Writes a formatted string to a specified output stream.
get_html_translation_table() Returns the translation table used by htmlspecialchars() and htmlentities().
hebrev() Converts Hebrew text into visible text.
hebrevc() Converts Hebrew text to visible text and converts newlines (\n) into
.
.
hex2bin() Converts a string of hexadecimal values into ASCII characters.
html_entity_decode() Converts HTML entities into characters.
htmlentities() Converts characters into HTML entities.
htmlspecialchars_decode() Converts some predefined HTML entities into characters.
htmlspecialchars() Converts some predefined characters into HTML entities.
implode() Returns a string formed by joining array elements.
join() Alias of implode().
lcfirst() Converts the first character of a string to lowercase.
levenshtein() Returns the Levenshtein distance between two strings.
localeconv() Returns local number and currency format information.
ltrim() Removes whitespace or other characters from the left side of a string.
md5() Calculates the MD5 hash of a string.
md5_file() Calculates the MD5 hash of a file.
metaphone() Calculates the metaphone key of a string.
money_format() Returns a string formatted as a currency string.
nl_langinfo() Returns the specified locale information.
nl2br() Inserts an HTML line break before each newline in a string.
number_format() Formats a number with grouped thousands.
ord() Returns the ASCII value of the first character in a string.
parse_str() Parses a query string into variables.
print() Outputs one or more strings.
printf() Outputs a formatted string.
quoted_printable_decode() Converts a quoted-printable string into an 8-bit string.
quoted_printable_encode() Converts an 8-bit string into a quoted-printable string.
quotemeta() Quotes meta characters.
rtrim() Removes whitespace or other characters from the right side of a string.
setlocale() Sets locale information.
sha1() Calculates the SHA-1 hash of a string.
sha1_file() Calculates the SHA-1 hash of a file.
similar_text() Calculates the similarity of two strings.
soundex() Calculates the soundex key of a string.
sprintf() Writes a formatted string into a variable.
sscanf() Parses input from a string according to a specified format.
str_getcsv() Parses a CSV string into an array.
str_ireplace() Replaces some characters in a string (case-insensitive).
str_pad() Pads a string to a new length.
str_repeat() Repeats a string a specified number of times.
str_replace() Replaces some characters in a string (case-sensitive).
str_rot13() Performs ROT13 encoding on a string.
str_shuffle() Randomly shuffles all characters in a string.
str_split() Splits a string into an array.
str_word_count() Counts the number of words in a string.
strcasecmp() Compares two strings (case-insensitive).
strchr() Finds the first occurrence of a string in another string. (Alias of strstr().)
strcmp() Compares two strings (case-sensitive).
strcoll() Compares two strings (according to locale settings).
strcspn() Returns the number of characters found in the string before any of the specified characters is found.
strip_tags() Strips HTML and PHP tags from a string.
stripcslashes() Removes backslashes added by the addcslashes() function.
stripslashes() Removes backslashes added by the addslashes() function.
stripos() Returns the position of the first occurrence of a string in another string (case-insensitive).
stristr() Finds the position of the first occurrence of a string in another string (case-insensitive).
strlen() Returns the length of a string. For processing Chinese strings, use the mb_strlen() function.
strnatcasecmp() Uses a "natural order" algorithm to compare two strings (case-insensitive).
strnatcmp() Uses a "natural order" algorithm to compare two strings (case-sensitive).
strncasecmp() Compares the first n characters of two strings (case-insensitive).
strncmp() Compares the first n characters of two strings (case-sensitive).
strpbrk() Searches a string for any of the specified characters.
strpos() Returns the position of the first occurrence of a string in another string (case-sensitive).
strrchr() Finds the last occurrence of a string in another string.
strrev() Reverses a string.
strripos() Finds the position of the last occurrence of a string in another string (case-insensitive).
strrpos() Finds the position of the last occurrence of a string in another string (case-sensitive).
strspn() Returns the number of specific characters contained in a string.
strstr() Finds the first occurrence of a string in another string (case-sensitive).
strtok() Splits a string into smaller strings.
strtolower() Converts a string to lowercase letters.
strtoupper() Converts a string to uppercase letters.
strtr() Translates specific characters in a string.
substr() Returns a part of a string.
mb_substr() Returns a part of a Chinese string.
substr_compare() Compares two strings from a specified start position (binary-safe and optionally case-sensitive).
substr_count() Counts the number of occurrences of a substring in a string.
substr_replace() Replaces a part of a string with another string.
trim() Removes whitespace and other characters from both sides of a string.
ucfirst() Converts the first character of a string to uppercase.
ucwords() Converts the first character of each word in a string to uppercase.
vfprintf() Writes a formatted string to a specified output stream.
vprintf() Outputs a formatted string.
vsprintf() Writes a formatted string into a variable.
wordwrap() Wraps a string to a specified length.