PHP String Connection _php Tutorial

Source: Internet
Author: User
Many times we need to concatenate a few strings to show that in PHP, the strings are connected using "dots", which is the period "." in English, using the following method:

Defining strings

$str 1 = "Hello world!";

$str 2 = "Welcome to Hutaow ' s blog!";

Connect the above two strings separated by a space

$str 3 = $str 1. " " . $STR 2;

Output the concatenated string

echo $str 3;

/*

After the code executes, the browser page will display

"Hello world! Welcome to Hutaow ' s blog! "

*/

?>

The connection string has another method, a bit like the "printf" placeholder in C, but PHP simply writes the variable name to the placeholder. The way to use this is to enclose the variable with curly braces, so that when displayed, the part of the string that is not enclosed in curly braces will still be output directly, and the enclosed part will be replaced with the corresponding string according to the variable name. You can see the following example more clearly, note the underlined part:

Define the string to be inserted

$author = "Hutaow";

Generate a new string

$str = "Welcome to {$author} ' s blog!";

Output $STR string

Echo $str; /*

After the code executes, the browser page will display

"Welcome to Hutaow ' s blog!"

*/

?>

Excerpt from: Shine's Sacred Paradise

http://www.bkjia.com/PHPjc/478624.html www.bkjia.com true http://www.bkjia.com/PHPjc/478624.html techarticle many times we need to concatenate a few strings to show that in PHP, the strings are concatenated using dots, that is, the period in English., using the following methods:? PHP//Definition ...

  • Related Article

    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.