Home > php教程 > php手册 > 详解PHP字符串的组成方式

详解PHP字符串的组成方式

WBOY
Release: 2016-06-13 11:07:01
Original
1196 people have browsed it

在进行其实PHP字符串就是 字符数组 假设我们定义一个字符串

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><strong><font color="#006699"></font></strong></span><span> </span></span></li>
<li class=""><span> </span></li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">string</font></span><span> =</span><span class="attribute-value"><font color="#0000ff">"hello world"</font></span><span>;  </span>
</li>
<li class=""><span> </span></li>
<li class="alt"><span>/*  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>这个PHP字符串是由 h , e , l ,  l , o , 空格 , w ,o,r,l,d 这几个字符组成  至于是以什么结尾的我现在能了解, 可能需要查看PHP原代码才能发掘  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>*/  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>//那我以上所说的有什么根据呢?下面可以测试  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>echo $string[2];//显示出第3个字符 l   ,我们可以尝试改变  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>$string[2]="A";//更改其中的 一个字符;  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>echo $string;// 得到 heAlo world  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>//那么我们可以尝试为  $string[2] 更改为字符串  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>$string[2]="AAAAAA";//测试 看看PHP会不会把 其后面的字符覆盖  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>echo $string;// 得到 heAlo world  ,呵呵 看来PHP做了安全处理  </span></li>
<li class=""><span> </span></li>
<li class="alt">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
</li>
</ol>
Copy after login

希望大家能够通过上面这段代码彻底弄清PHP字符串的组成原理。


source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template