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

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

PHP中文网
PHP中文网Original
2018-05-02 10:51:496288browse

explode

Function: Use one string to split another string

Syntax:

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

Parameters:

delimiter The delimiter character on the boundary.
string The 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; // *

?>

返回示例

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

?>


打印结果

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

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

打印结果

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

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