In either language, string manipulation is an important foundation, often simple and important. Just as people speak, there is a body (graphical interface), there is a language (print string?). Clearly, the string can explain more things. PHP provides a large number of string manipulation functions, powerful and easy to use. The following will briefly describe its functionality and characteristics.
Weak type
PHP is a weakly typed language, so other types of data can generally be applied directly to string manipulation functions and automatically converted to string types for processing, such as:
echo substr ("1234567", 1, 3);
And
Echo substr (123456,1, 3);
is the same
Defined
A string is typically identified with double or single quotes. Like what
$str = "I love u";
$str = ' I love u ';
There are some differences between the two. The latter treats all single quotes as characters; Like what
$test = "Iwind";
$str = "I love $test";
$str 1 = ' I love $test ';
Echo $str; Will get I love Iwind
echo $str 1; Will get I love $test
The same behavior of the following two examples is not the same:
echo "I love \test"; Will get I love est, which already treats \ t as escaping
Echo ' I love \test '; Will get I love \test
It is possible to simply assume that the contents of the double quotes are "explained" and that single quotes are "WYSIWYG" (particularly, ' will be considered a '). Obviously, the double quotes form is more flexible, of course, single quotes will apply to some special occasions, this is not explained here.
Output
The most common use of output in PHP is echo,print. Both are not real functions, but language constructs, so it is not necessary to invoke a double parenthesis (such as echo ("test");p rint ("Test"). Both can be assigned at the time of output:
echo $str = "Test"; On the one hand output test, on the one hand "test" to the string variable $str
Print $str = "Test";