Strings are concatenations or series of characters that you cannot see at once when searching for something. Instead, you have to look one by one and keep track of what the content is. PHP has many predefined functions that help you in interacting with strings. Characters are letters, numbers, and punctuation. When a number is used as a character, it is just a stored character, the same as a letter. It can’t be used in arithmetic.

strlen: This function returns the number of characters that the string contains.

trim: This function returns the string, removing all the blank spaces to the left and to the right.

strtoupper and strtolower: These functions return the string with all the characters in upper or lower case respectively.

str_replace: This function replaces all occurrences of a given string by the replacement string.

substr: This function extracts the string contained between the positions specified by parameters, with the first character being at position 0.

strpos: This function shows the position of the first occurrence of the given string. It returns false if the string cannot be found.

Additionally, there is an operator for strings (.) which concatenates two strings.

Single Quotes or Double Quotes

You can enclose strings within single quotes or double quotes. The difference is that within single quotes, a string is exactly as it is represented, but within double quotes, some rules are applied before showing the final result. There are two elements that double quotes treat differently than single quotes: escape characters and variable expansions.

Escape characters: These are special characters than cannot be represented easily. Examples of escape characters are new lines or tabs. To represent them, you use escape sequences, which are the concatenation of a backslash (\) followed by some other character. For example, \n represents a new line, and \t represents a tabulation.

Variable expanding: This allows you to include variable references inside the string, and PHP replaces them by their current value. You have to include the $ sign too.

How To Join Strings

You can join strings, a process called concatenation, by using a dot (.).