PHP string connection _ PHP Tutorial

Source: Internet
Author: User
PHP string connection. In most cases, we need to connect several strings and display them. in PHP, strings are connected by dots, that is, periods in English. the specific usage is as follows :? When defining php, we often need to connect several strings to display them. in PHP, strings are connected by "points", that is, periods in English. ". the usage 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:

// 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! "

*/

?>

From: Shine's holy heaven

Why :? Php // definition...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.