Home > Backend Development > PHP Tutorial > php, explode php separate string into array

php, explode php separate string into array

巴扎黑
Release: 2016-11-24 14:06:09
Original
1180 people have browsed it

explode

explode — Use one string to split another string
array explode ( string $separator , string $string [, int $limit ] )

This function returns an array composed of strings, each element is A substring of string, which is separated by string separator as a boundary point. 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 an empty string (""), explode() will return FALSE. If separator contains a value not found in string, explode() returns an array containing a single element of string.

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

Due to historical reasons, although implode() can receive two parameter orders, explode() cannot. You must ensure that the separator parameter comes before the string parameter.

Note: When constructing the sql statement, the query column can be written like this

Php code

$field = explode( ':','*');// I only learned about the usage of explode today



Official demo :

Php code

<?php  
// 示例 1  
$pizza  = "piece1 piece2 piece3 piece4 piece5 piece6";  
$pieces = explode(" ", $pizza);  
echo $pieces[0]; // piece1  
echo $pieces[1]; // piece2  
  
// 示例 2  
$data = "foo:*:1023:1000::/home/foo:/bin/sh";  
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);  
echo $user; // foo  
echo $pass; // *  
  
?>
Copy after login


Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template