1. String variable
String variable is used to store and process text
<?php $a = "hello world" ; echo $a; ?>
Create a string named a variable and assign the value to "Hello world!". Then we output the value of a variable
The concatenation operator in the string
There is only one concatenation operator in the string " . " Is this right? Two strings are linked together
<?php $a = "hello world"."! welcome" ; echo $a; ?>
strlen() function
Sometimes it is useful to know the length of the string value
<?php $a = "hi hello world"; echo strpos($a,'l'); ?>
Note: The number of characters is only 12, but there are 2 spaces. Spaces are also characters. The output result is 14
strpos() function
strpos() function is used to find a character or a specified piece of text in a string
<?php $a = "hi hello world"; echo strpos($a,'l'); ?>
Note: The subscript of the string starts with 0, that is, the position of h in the above code is 0, Then the position of l is in the fifth position, so the output is 5 instead of 6
There are many functions that operate on strings in php, as shown in the figure below
For specific usage, please refer to the manual or Baidu
Next Section