PHP separates string into array_PHP tutorial
Jul 13, 2016 pm 05:45 PM
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
<?php
// 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"

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
