$ string_2 = "Learning PHP transfer technology in QTM";
$ string_0 = ""; // for example, a string with no characters
When using a string with single quotes, it will be treated as constants, and print the same string. While using with quotation marks, it replaces variables with their values as well as interprets specific character sequences.
";
$ bien_chuoi_hang = "The string $ bien_chuoi will be printed! n";
print ($ bien_chuoi_hang);
?>
Save the above program in a file named test.php in htdocs , then open the browser and type the address http:/// localhost: 8080 / test.php will result:
There is no limit to the length of the string, it can be arbitrarily long if the memory allows.
Strings limited by double quotes are handled by PHP in two ways:
To join two strings together, you use the operator. (dots) in PHP are as follows:
Save the above program in a file named test.php in htdocs , then open the browser and type the address http:/// localhost: 8080 / test.php will result:
Web QTM
If you pay attention to the above code, you will see that we used the string concatenation operator twice. This is because we have inserted a third string.
Between two string variables, we add a string with a single character, which is a space, to distinguish the two variables.
The strlen () function in PHP is used to find the length of a string.
The following example will find the length of the string "QTM Nhom!":
Save the above program in a file named test.php in htdocs , then open the browser and type the address http:/// localhost: 8080 / test.php will result:
8
The length of a string is often used in loops or other functions, when it is important to know when the string ends (for example, in a loop, we want to stop the loop after the last character of Chain).
The strops () function is used to find a string or character inside a string.
If a match is found, this function returns the position of the first match. If no match is found, it returns FALSE.
Now we find the "QTM" string in the "Web QTM!" String:
Save the above program in a file named test.php in htdocs , then open the browser and type the address http:/// localhost: 8080 / test.php will result:
4
As you can see, the position of the string "QTM" in the above string is 4. The reason is 4 but not 5, because the first position of the string is 0, not 1.
Follow tutorialspoint
Previous post: Array (Array) in PHP
Next lesson: Insert file in PHP