With the development of the times, our development technology has also been updated. PHP is still relatively commonly used, so I studied PHP array conversion to string, and I will share it with you here. I hope it will help Useful to everyone.
1, how to convert a character into an array
Solution: str_split() function
The example is as follows:
<ol class="dp-xml"> <li class="alt"><span><span>$</span><span class="attribute"><font color="#ff0000">biuuu</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">'www.biuuu.com'</font></span><span>; </span></span></li> <li class=""><span>print_r(str_split($biuuu)) </span></li> </ol>
Output result:
<ol class="dp-xml"> <li class="alt"><span><span>Array </span></span></li> <li class=""><span>( </span></li> <li class="alt"> <span>[0] =</span><span class="tag"><strong><font color="#006699">></font></strong></span><span> b </span> </li> <li class=""> <span>[1] =</span><span class="tag"><strong><font color="#006699">></font></strong></span><span> i </span> </li> <li class="alt"> <span>[2] =</span><span class="tag"><strong><font color="#006699">></font></strong></span><span> u </span> </li> <li class=""> <span>[3] =</span><span class="tag"><strong><font color="#006699">></font></strong></span><span> u </span> </li> <li class="alt"> <span>[4] =</span><span class="tag"><strong><font color="#006699">></font></strong></span><span> u </span> </li> <li class=""><span>) </span></li> </ol>
2. How to convert a php array to a string
Solution: implode() function
The example is as follows:
<ol class="dp-xml"> <li class="alt"><span><span>$</span><span class="attribute"><font color="#ff0000">biuuu</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">array</font></span><span>('b','i','u','u','u'); </span></span></li> <li class=""><span>print_r(implode('',$biuuu)); </span></li> </ol>
Output result biiuu
3, how to find another character
in one character Solution: strpos or strstr
Example is as follows:
<ol class="dp-xml"> <li class="alt"><span><span>$</span><span class="attribute"><font color="#ff0000">biuuu</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">'this is my website biuuu.com'</font></span><span>; </span></span></li> <li class=""> <span>$</span><span class="attribute"><font color="#ff0000">search</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">'biuuu'</font></span><span>; </span> </li> <li class="alt"><span>print_r(strpos($biuuu,$search)); </span></li> </ol>
Output result: 19
4, how to get certain characters in the characters
Solution: substr() function
Example is as follows:
<ol class="dp-xml"> <li class="alt"><span><span>$</span><span class="attribute"><font color="#ff0000">biuuu</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">'this is my website biuuu.com'</font></span><span>; </span></span></li> <li class=""><span>print_r(substr($biuuu,19)); </span></li> </ol>
Output result: biuuu.com
5, how to get the character length
Solution: strlen() function
The example is as follows:
<ol class="dp-xml"> <li class="alt"><span><span>$</span><span class="attribute"><font color="#ff0000">biuuu</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">'this is my website biuuu.com'</font></span><span>; </span></span></li> <li class=""><span>print_r(strlen($biuuu)); </span></li> </ol>
Output result 28
The above PHP character processing functions str_split, implode, strpos, substr and strlen are often used in actual development. I hope they will be helpful to everyone.