Home >Backend Development >PHP Tutorial >Detailed explanation of how PHP strings are composed_PHP tutorial

Detailed explanation of how PHP strings are composed_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:30:02884browse

in progressIn fact, PHP string is a character array. Suppose we define a string

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

Hope everyone can pass The above code completely understands the composition principle of PHP strings.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446321.htmlTechArticleIn progress In fact, PHP string is a character array. Suppose we define a string? $ string = "helloworld" ; / * This PHP string is composed of the characters h, e, l, l, o, space, w, o, r, l, d...
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