当前位置:Gxlcms > PHP教程 > explode函数使用说明

explode函数使用说明

时间:2021-07-01 10:21:17 帮助过:4人阅读

  1. // 示例 1

  2. $pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
  3. $pieces = explode(" ", $pizza);
  4. echo $pieces[0]; // piece1
  5. echo $pieces[1]; // piece2

  6. // 示例 2

  7. $data = "foo:*:1023:1000::/home/foo:/bin/sh";
  8. list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
  9. echo $user; // foo
  10. echo $pass; // *
  11. ?>

例 2. limit 参数例子

  1. $str = 'one|two|three|four';

  2. // 正数的 limit

  3. print_r(explode('|', $str, 2));

  4. // 负数的 limit(自 PHP 5.1 起)

  5. print_r(explode('|', $str, -1));
  6. ?>

上例将输出: Array ( [0] => one [1] => two|three|four ) Array ( [0] => one [1] => two [2] => three )

人气教程排行