PHP-MySQL Connectivity
Strings are the collection of Characters. Common Built-in PHP String Functions are:
Function | Description |
---|---|
strlen() | The PHP strlen() function returns the length of a string. Syntax: echo strlen("Hello world!"); |
str_word_count() | The PHP str_word_count() function counts the number of words in a string: Syntax: echo str_word_count("Hello world!"); |
strrev() | Reverses a string Syntax: echo strrev("Hello world!"); |
strpos() | Searches for a specific text within a string. If a match is found, the function returns the character position of the first match. If no match is found, it will return FALSE. Syntax: echo strpos("Hello world!", "world"); |
str_replace() | Replaces some characters with some other characters in a string. Syntax: echo str_replace("world", "Dolly", "Hello world!"); |
strchr() | Searches for the first occurrence of a string inside another string. Syntax: echo strchr("Hello world!","world"); |
strcmp() | Compare two strings (case-sensitive): Syntax: echo strcmp("Hello world!","Hello world!"); |
strcasecmp() | Compares two strings (case-insensitive) |
strncmp() | String comparison of the first n characters (case-sensitive) |
strtolower() | Converts a string to lowercase letters |
strtoupper() | Converts a string to uppercase letters |
str_shuffle() | Shuffles all characters in a string Randomly. |
str_repeat() | Repeats a string upto specified number of times. |
substr() | Returns a part of a string. |
trim() | Removes whitespace or 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 |
wordwrap() | Wraps a string to a given number of characters |