<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html>
  <head>
   <title> explode_implode.php </title>
   <meta charset="UTF-8">
   <meta name="Author" content="">
   <meta name="Keywords" content="">
   <meta name="Description" content="">
  </head> <body>
<?php
 echo "通过空格分隔字符串:<br>";
 $pizza = "a1 a2 a3 a4 a5 a6";
 //通过空格分隔
 $pieces = explode(" ", $pizza);
 //输出返回数组的头两个元素
 echo $pieces[0] . "<BR>"; // 输出a1
 echo $pieces[1]. "<BR>"; // 输出a2
 // 将分隔后的元素保存到list 的变量中
 echo "将变量保存在list 变量中:<br>";
 $data = "foo:*:1023:1000::/home/foo:/bin/sh";
 list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
 echo $user. "<BR>"; // 输出foo
 echo $pass. "<BR>"; // 输出*
 echo "限制分隔的字符串数:<BR>";
 $limit="a;b;c;d;e;f;";
 $back=explode(";",$limit,3);
 print_r($back);
 ?>
 <hr>
 <?php
 $myarray = array('lastname', 'email', 'phone');
 //用逗号分隔符连接数组
 $comma_separated = implode(",", $myarray);
 echo $comma_separated;
 ?> </body>
 </html>


通过空格分隔字符串:
a1
a2
将变量保存在list 变量中:
foo
*
限制分隔的字符串数:
Array ( [0] => a [1] => b [2] => c;d;e;f; )
lastname,email,phone