Home  >  Article  >  Backend Development  >  explode function instructions

explode function instructions

WBOY
WBOYOriginal
2016-07-25 08:52:101374browse
  1. // Example 1

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

  6. // Example 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. ?>

Copy code

Example 2. limit parameter example

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

  2. // Positive limit

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

  4. // Negative limit (since PHP 5.1)

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

Copy the code

The above example will output: Array ( [0] => one [1] => two|three|four ) Array ( [0] => one [1] => two [2] => three )



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