Home headlines Summary of php explode() function definition and usage (2021)

Summary of php explode() function definition and usage (2021)

May 02, 2018 am 10:51 AM
php

explode

Function: Use one string to split another string

Syntax:

explode ( string $delimiter , string $string [, int $limit ] ) : array
Copy after login

Parameters:

delimiterThe delimiter character on the boundary.
stringThe input string.
limit

If the limit parameter is set and is a positive number, the returned array contains at most limit elements, and the last element will contain the remainder of the string part.

If the limit parameter is a negative number, all elements except the last -limit elements are returned.

If limit is 0, it will be treated as 1.

返回值:

此函数返回由字符串组成的 array,每个元素都是 string 的一个子串,它们被字符串 delimiter 作为边界点分割出来。

如果 delimiter 为空字符串(""),explode() 将返回 FALSE。 如果 delimiter 所包含的值在 string 中找不到,并且使用了负数的 limit , 那么会返回空的 array, 否则返回包含 string 单个元素的数组。


explode 示例

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

返回示例

<?php
/* A string that doesn&#39;t contain the delimiter will simply return a one-length array of the original string. */
$input1 = "hello";
$input2 = "hello,there";
var_dump( explode( &#39;,&#39;, $input1 ) );
var_dump( explode( &#39;,&#39;, $input2 ) );

?>
Copy after login


打印结果

array(1)
(
    [0] => string(5) "hello"
)
array(2)
(
    [0] => string(5) "hello"
    [1] => string(5) "there"
)
Copy after login

limit 示例

<?php
$str = &#39;one|two|three|four&#39;;

// 正数的 limit
print_r(explode(&#39;|&#39;, $str, 2));

// 负数的 limit(自 PHP 5.1 起)
print_r(explode(&#39;|&#39;, $str, -1));
?>
Copy after login

打印结果

Array
(
    [0] => one
    [1] => two|three|four
)
Array
(
    [0] => one
    [1] => two
    [2] => three
)
Copy after login

explode 问题

1. php explode()函数和implode()函数使用说明

简介:下里说道php中的explode 和implode的用法,芭蕾舞鞋,盼望对于友朋们有所辅助!

2. php explode()函数的用法说明

简介:下面是根据explode()函数写的切分分割字符串的php函数,主要php按开始和结束截取中间数据,很实用

3. php explode函数的用法

简介:这篇文章主要介绍了php中explode函数用法,实例分析了explode函数分割字符串及获取文件后缀名等应用,具有一定的参考借鉴价值,需要的朋友可以参考下

4. 有关php explode()函数的文章推荐10篇

Summary of php explode() function definition and usage (2021)

简介:本文实例讲述了php根据年月获取当月天数及日期数组的方法。分享给大家供大家参考,具体如下:function get_day( $date ) { $tem = explode('-' , $date); //

5. php explode() 函数的用法总结

Summary of php explode() function definition and usage (2021)

简介:php中,explode() 函数是把字符串分割为数组。本它的返回值是返回由字符串组成的数组,其中的每个元素都是由 separator 作为边界点分割出来的子字符串。本篇文章总结了一些关于php explode() 函数的一些文章,希望对大家学习php explode() 函数有所帮助。

6. php explode()函数的使用方法

Summary of php explode() function definition and usage (2021)

简介:在php中分割一个字符串,我们可以使用函数explode()实现,通常我们在开发项目中,想查看用户通过表单或者其它方式提交的字符串的各个部分,以便于分类存储和使用。例如,查看句子中的单词,或者要将一个网址或者电子邮箱地址分割成一个个的组成部分。这时我们就可以使用explode()函数,本篇文章就来介绍一下php explode()函数的使用方法

7. php explode() 函数实例详解

Summary of php explode() function definition and usage (2021)

简介:php explode() 函数有什么作用?  php explode() 函数是:使用一个字符串分割另一个字符串,并返回由字符串组成的数组。  了解了 explode() 函数是干嘛的,下面看一下语法吧:

8. PHP explode 函数

Introduction:: This article mainly introduces the PHP explode function. Students who are interested in PHP tutorials can refer to it.

9. php explode function explanation

Introduction::This article mainly introduces the explanation of php explode function. Students who are interested in PHP tutorials can refer to it.

10. explode and implode functionsexplode implode cad explode php explode function

Introduction:explode:explode and implode Functions: The explode and implode functions are mainly used for conversion operations between strings and arrays, such as splitting a string according to a certain character after obtaining a parameter, or merging the results of an array into a string using one character for output. These two functions are often used in PHP, so it is necessary to understand their principles. explodearray explode ( string $delimiter, string $string, [ , $limit ]) function returns an array composed of strings, each element

11. php explode php explode Function example code

#Introduction: php explode:php explode php explode function example code: explode() function splits a string into an array. Syntax explode(separator,string,limit) Parameter description separator is required. Specifies where to split the string. string required. The string to split. limit is optional. Specifies the maximum number of array elements returned. Description This function returns an array composed of strings, each element of which is a substring separated by separator as a boundary point. The separator parameter cannot be an empty string

12. php explode function example code_PHP tutorial

Introduction: php explode function example code. The explode() function splits a string into an array. Syntax explode(separator,string,limit) Parameter Description separator Required. Specifies where to split the string. string required. Characters to be split

13. PHP explode() function usage, splitting string_PHP tutorial

Introduction: PHP explode() function usage and splitting strings. Copy the code as follows: ? // Split the string

# function jb51netcut($start,$end,$file){ $content=explode($start,$file); $content=explode($ end,$content[1]); return $content

##14. PHP explode() String Conversion Array_PHP Tutorial

Introduction: PHP explode() string conversion array. There are many ways to convert strings into arrays in PHP. If we have regularity, we can directly use the explode() function to cut the string into an array. Definition and usage explode() function

15. php explode split str_split function difference and examples_PHP tutorial

Introduction: Differences and examples of php explode split str_split function. PHP tutorial explode split str_split function difference and examples. The three functions all split a string into an array, but each has its own usage. Let’s take a look at php expl

# one by one. ##16. Several applications of PHP explode() function_PHP tutorial

Introduction: Several applications of PHP explode() function. Introduction to explode() function The explode() function can split a string into an array. Syntax: explode(separator,string,limit). separator, required. Specifies where to split the string. string,

17. What are the differences between several applications of PHP explode() function and implode() function, explodeimplode_PHP tutorial

Introduction: What are the differences between several applications of the PHP explode() function and the implode() function, explodeimplode. What are the differences between several applications of the PHP explode() function and the implode() function? Introduction to the explode() function. The explode() function can split a string into an array. Syntax: explode(sep

##18. php explode function explanation, phpexplode function_PHP tutorial

Introduction: Explanation of php explode function, phpexplode function. Explanation of php explode function, phpexplode function This article reprint address: http://www.manongjc.com/article/515.html The php explode function uses one string to split another string, and the split

19. php explode() function

Introduction: php explode() function

##20. php explode function tutorial

Introduction: php explode function explanation This article’s reprint address: http://www.manongjc.com/article/515.html php explode function Use one string to split another string, the split strings will be combined into an array, and this array will be returned. This article introduces you to the basic syntax and usage examples of the explode function. Coders in need can refer to it. explode uses

21. php explode function example code

Introduction: php explode function example code. The explode() function splits a string into an array. Syntax explode(separator,string,limit) Parameter Description separator Required. Specifies where to split the string. string required. Characters to be split

22. PHP explode() function usage, splitting string

Introduction: PHP explode() function usage, splitting strings. Copy the code as follows: ? // Split the string # function jb51netcut($start,$end,$file){ $content=explode($start,$file); $content=explode($ end,$content[1]); return $content

23. PHP explode() string conversion array

Introduction: PHP explode() string conversion array. There are many ways to convert strings into arrays in PHP. If we have regularity, we can directly use the explode() function to cut the string into an array. Definition and usage explode() function

24. php explode split str_split function difference and examples

Introduction: Differences and examples of php explode split str_split function. PHP tutorial explode split str_split function difference and examples. The three functions all split a string into an array, but each has its own usage. Let’s take a look at php expl

# one by one. ##25. Several applications of the PHP explode() function

Introduction: Several applications of the PHP explode() function. Introduction to explode() function The explode() function can split a string into an array. Syntax: explode(separator,string,limit). separator, required. Specifies where to split the string. string,

[Related Q&A recommendations]:

javascript - I would like to ask if there is a function similar to PHP explode in js or juqery?

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

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

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 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

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

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.