1. String variables are used to store and process text;
2. The string variable is used to contain the value of the character, after creating the string, you can manipulate it, you can use the string directly in the function, or store it in a variable;
<?php
$txt = "Hello World"; When you assign a text value to a variable, remember the text value plus single or double quotation marks
Echo $txt;
?>
2. Functions and operators for manipulating strings:
(1) PHP's collocated operator: in PHP, there is only one string operator: the collocated operator (.), which is used to concatenate two string values together:
<?php
$txt 1= "Hello World";
$txt 2= "What a nice day!";
echo $txt 1. " ". $txt 2;
?>
(2) PHP strlen () function: strlen function returns the length of the string (number of characters)
<?php
Echo strlen ("Hello world!"); Strlen () is often used in loops and other functions because it is important to determine when the string ends;
?>
(3) PHP Strpos () function: the Strpos () function is used to find a string or a specified text within a string;
If a match is found in the string, the function returns the first matching character position and returns False if no match is found;
<?php
Echo Strpos ("Hello world!", "World"); The position of "world" is 6, not 7, because the first position of the string is 0, not 1
?>
PHP Learning String