Home  >  Article  >  Backend Development  >  How to write actual code for PHP string concatenation_PHP tutorial

How to write actual code for PHP string concatenation_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:29:56845browse

To connect multiple strings, use a (.) "dot" sign, for example:

<ol class="dp-xml"><li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN>   </SPAN></SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>name</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>"w3pop"</FONT></SPAN><SPAN>;   </SPAN></SPAN><LI class=alt><SPAN>echo $name.".com";   </SPAN><LI class=""><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong></span><span>   </span>
</li></ol>

The above output result is w3pop.com

There is a situation of PHP string connection. When echo is followed by (") double quotes, you can achieve the same effect as above:

<ol class="dp-xml"><li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN>   </SPAN></SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>name</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>"w3pop"</FONT></SPAN><SPAN>;//这句一样   </SPAN></SPAN><LI class=alt><SPAN>echo "$name.com";//双引号里的变量还是可以正常显示出来,<br>并和一般的字符串自动区分开来   </SPAN><LI class=""><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong></span><span>   </span>
</li></ol>

But if it is a single quote, the content inside will be output to the browser completely in string form:

<ol class="dp-xml"><li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN>   </SPAN></SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>name</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>"w3pop.com"</FONT></SPAN><SPAN>;   </SPAN></SPAN><LI class=alt><SPAN>echo '$name.com';   </SPAN><LI class=""><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong></span><span>   </span>
</li></ol>

will display $name.com

PHP string concatenation example code:

<ol class="dp-xml">
<li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN>   </SPAN></SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>name</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>"w3pop"</FONT></SPAN><SPAN>;   </SPAN></SPAN><LI class=alt><SPAN>echo $name.".com";   </SPAN><LI class=""><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong></span><span>   </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>br</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=tag><STRONG><FONT color=#006699>/></span></font></strong><span>   </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN>   </SPAN></SPAN><LI class=alt><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>name</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>"w3pop"</FONT></SPAN><SPAN>;   </SPAN></SPAN><LI class=""><SPAN>echo "$name.com";   </SPAN><LI class=alt><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong><span>   </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>br</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=tag><STRONG><FONT color=#006699>/></span></font></strong><span>   </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN>   </SPAN></SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>name</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>"w3pop.com"</FONT></SPAN><SPAN>;   </SPAN></SPAN><LI class=alt><SPAN>echo '.com';   </SPAN><LI class=""><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong><span>   </span>
</li>
</ol>

Output result

w3pop.com

w3pop.com.com

$name.com

How about it? Through the demonstration of the above three pieces of code, have you mastered the method of PHP string connection?


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446324.htmlTechArticleTo connect multiple strings, you need to use a (.) "dot" sign, such as: ? php $ name = "w3pop" ; echo$name.".com"; ? The above output is w3pop.com. There is a PHP string connection...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn