Home Backend Development PHP Tutorial PHP separates string into array_PHP tutorial

PHP separates string into array_PHP tutorial

Jul 13, 2016 pm 05:45 PM
array explode php string for use Split separate string array

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"

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 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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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

See all articles