Published by: Sujan
Published date: 16 Jun 2021
A string in PHP is a sequence of letters, numbers, special characters, and arithmetic values or a combination of all. The simplest way to create a string is to enclose the string literal (i.e. string characters) in single quotation marks ('), like this:
$my_string = 'Hello World';
You can also use double quotation marks ("). However, single and double quotation marks work in different ways. Strings enclosed in single quotes are treated almost literally, whereas the strings delimited by the double quotes replace variables with the string representations of their values as well as specially interpreting certain escape sequences.
The escape-sequence replacements are:
The strlen() function is used to calculate the number of characters inside a string. It also includes the blank spaces inside the string.
The str_word_count() function counts the number of words in a string.
The str_replace() replaces all occurrences of the search text within the target string.
The output of the above code will be:
If the truth does not fit the theory, change the truth.
The strrev() function reverses a string.