Rumah > pembangunan bahagian belakang > tutorial php > PHP字符串连接的实际代码编写方式_PHP教程

PHP字符串连接的实际代码编写方式_PHP教程

WBOY
Lepaskan: 2016-07-15 13:29:56
asal
854 orang telah melayarinya

要让多个字符串进行衔接,要用到一个(.)“点”号,比如:

<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>
<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>
</li>
<li class="alt"><span>echo $name.".com";   </span></li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span>   </span>
</li>
</ol>
Salin selepas log masuk

上面的输出结果就是w3pop.com

有一种PHP字符串连接的情况,当echo后面使用的是(")双引号的话可以这样来达到和上同样的效果:

<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>
<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>
</li>
<li class="alt"><span>echo "$name.com";//双引号里的变量还是可以正常显示出来,<br>并和一般的字符串自动区分开来   </span></li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span>   </span>
</li>
</ol>
Salin selepas log masuk

但如果是单引号的话,就会将里面的内容完全以字符串形式输出给浏览器:

<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>
<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>
</li>
<li class="alt"><span>echo '$name.com';   </span></li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span>   </span>
</li>
</ol>
Salin selepas log masuk

将显示$name.com

PHP字符串连接示例代码:

<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>
<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>
</li>
<li class="alt"><span>echo $name.".com";   </span></li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span>   </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">br</span></span></font></strong><span> </span><span class="tag"><strong><font color="#006699">/></font></strong></span><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>
</li>
<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>
</li>
<li class=""><span>echo "$name.com";   </span></li>
<li class="alt">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span>   </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">br</span></span></font></strong><span> </span><span class="tag"><strong><font color="#006699">/></font></strong></span><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>
</li>
<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>
</li>
<li class="alt"><span>echo '.com';   </span></li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span>   </span>
</li>
</ol>
Salin selepas log masuk

输出结果

w3pop.com

w3pop.com.com

$name.com

怎么样,大家通过上面这三段代码的演示,是否已经初步掌握了PHP字符串连接的方法了呢?


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446324.htmlTechArticle要让多个字符串进行衔接,要用到一个(.)“点”号,比如: ? php $ name = "w3pop" ; echo$name.".com"; ? 上面的输出结果就是w3pop.com 有一种PHP字符串连接...
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan