This article mainly introduces a simple example of PHP string connection. If you need a simple example, you can refer to it. Many times we need to connect several strings to display them. In PHP, use "points" to connect strings, that is, periods in English ". the usage is as follows:
The Code is as follows:
// Define a string
$ Str1 = "Hello World! ";
$ Str2 = "Welcome to huaow's BLOG! ";
// Separate the two strings with spaces
$ Str3 = $ str1. "". $ str2;
// Output the connected string
Echo $ str3;
/*
After the code is executed, the browser page is displayed.
"Hello World! Welcome to huaow's BLOG! "
*/
?>
There is another way to connect the string, which is a bit like the Placeholder "printf" in C, but PHP directly writes the variable name to the placeholder. In this way, braces are added before and after the variable. When the variable is displayed, the portion of the string that is not enclosed by braces will still be directly output, the enclosed part will replace the corresponding string according to the variable name. You can see the following example to make it clearer. Pay attention to the underlined part:
The Code is as follows:
// Define the string to be inserted
$ Author = "huaow ";
// Generate a new string
$ Str = "Welcome to {$ author}'s BLOG! ";
// Output $ str string
Echo $ str ;/*
After the code is executed, the browser page is displayed.
"Welcome to huaow's BLOG! "
*/
?>