String (String) in PHP
The string is a sequence of characters, just like "Learn PHP with QTM technology".
Note - You will find available string processing functions in PHP at PHP String (String)
Below is an example of valid strings in PHP.
$ string_1 = "In PHP";
$ 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:
- Character strings beginning with a forward slash () are replaced with special characters
- Variable names (starting with $) are replaced by the string representation of its value.
Replacement rules: - n is replaced with newline character (new line)
- The r is replaced by the carriage-return character, which is meant to bring the cursor to the beginning of the line but not the line.
- t is replaced by tab characters
- $ is replaced with a $ sign
- "replaced with a quotation mark"
- is replaced with a backslash
String concatenation operator in PHP
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.
Find the string length in PHP with strlen () in PHP
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).
Find the character or string in the string - strpos () function in PHP
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
You should read it
- string.h in C
- String object in JavaScript
- Some ways to tie the pole or everyone should know
- String in C
- How to Manipulate Strings in Java
- Find, FindB functions in Excel - The function finds a text string in another document in Excel
- MID and MIDB functions to cut strings in Excel
- The function takes a string in Excel
May be interested
- How to Manipulate Strings in Javastrings are sequences of characters. for example, 'hello!' is a string because it is made up of the characters 'h', 'e', 'l', 'l', 'o', and '!'. in java, strings are objects, which means that there is a string class that has fields and...
- How to insert characters at the beginning or end of a string in Excelrecently software tips received many questions asking how to insert characters at the beginning or end of a string in excel. so today, dexterity software introduces readers how to insert more characters into the string in this article, invite you to track.
- Write a program to reverse a string in Pythonwhat is string reversal in python? how to use the string reverse function in python? let's find out with tipsmake.com.com!
- The LEFT function, how to use the left-hand string cutting function in Excelthe left function in excel is used to trim the left string of characters in data parameters.
- Make changes in Gitjerry creates a copy of the repository on his machine and decides to perform basic operations. so he created the file string.c. after adding content, string.c will look like s
- Who would have thought that the production process of the familiar familiar string was complicated and such a feata familiar string, items that we still use every day to tie and pack goods. its presence is considered by everyone to be obvious, but most people don't know how the string is produced.
- How to use ConcateNate function on Excelconcatenate function on excel is a function that connects strings of characters in different data columns in a table, forming a complete string of characters.
- Analysis of an attack (Part 2)we have already introduced you in a section of observable information while opening the package string sent by nmap. the sent string starts with an icmp echo response to determine if the computer or network has been assigned to the ip address. add v & agr
- Python data type: string, number, list, tuple, set and dictionaryin this section, you'll learn how to use python as a computer, grasp python's data types and take the first step towards python programming.
- CONCATENATE function (string concatenation function) in Exceluse the concatenate function when you want to concatenate existing text strings into a single, complete text string. for the syntax and usage of the concatenate function, follow the article below.