Home  >  Article  >  Backend Development  >  PHP separates string into array_PHP tutorial

PHP separates string into array_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:45:16843browse

explode

explode — Split one string into another
array explode ( string $separator , string $string [, int $limit ] )

This function returns an array of strings, each element is a substring of string, and they are separated by string separator as boundary points. If the limit parameter is set, the returned array contains up to limit elements, and the last element will contain the remainder of the string.

If separator is the empty string (""), explode() returns FALSE. If separator contains a value not found in string, explode() returns an array containing a single element of string.

If the limit argument is negative, all but the last -limit elements are returned. This feature is new in PHP 5.1.0.

For historical reasons, while implode() can accept both argument orders, explode() cannot. You must ensure that the separator parameter comes before the string parameter.

Note: When constructing a sql statement, the query column can be written like this
Php code
$field = explode( ':','*');// I just learned how to use explode today


Official demo:
Php code
// Example 1
$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2

// Example 2
$data = "foo:*:1023:1000::/home/foo:/bin/sh";
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
echo $user; // foo
echo $pass; // *

?>

This article comes from "pengjun1128"

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478674.htmlTechArticleexplode explode Use one string to split another string array explode ( string $separator , string $string [, int $limit ] ) This function returns an array of strings, each...
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