首页 > php框架 > 分析PHP函数explode如何将字符串转换为数组

分析PHP函数explode如何将字符串转换为数组

我们在学习
1.PHP函数explode的格式如下:

array explode(string separator, string string,[int limit]);

2.参数中的separator为分隔符,string为待分割的字符串,limit为返回的数组中元素的最大个数。

PHP函数explode的具体使用实例:

  1. <?php 
  2.     $DOCUMENT_ROOT = $_SERVER[DOCUMENT_ROOT];  
  3. ?> 
  4. <html> 
  5.     <head> 
  6.         <title>Test Explode</title> 
  7.     </head> 
  8.     <body> 
  9.         <?php 
  10.             $peoples = file($DOCUMENT_ROOT./test/03/people.txt);  
  11.             $countcount = count($peoples);  
  12.             if ($count == 0) {  
  13.                 echo NO peoples pending. Please try again later.;  
  14.             }  
  15.             for ($i = 0; $i < $count; $i++) {  
  16.                 $line = explode(t, $peoples[$i]);  
  17.                 echo <font color=red>.$line[0].</font>;  
  18.                 echo <font color=blue>.$line[1].</font>;  
  19.                 echo <font color=green>.$line[2].</font>;  
  20.                 echo <br />;  
  21.             }  
  22.         ?> 
  23.     </body> 
  24. </html> 

希望广大学习爱好者们通过本文所介绍的PHP函数explode的使用示例,能够基本弄清PHP函数explode的使用方法。


教程网址:http://www.phprm.com/frame/php1003634.html

欢迎收藏∩_∩但请保留本文链接。

标签:none

发表留言