Home
Backend Development
PHP Tutorial
PHP explode() function usage and splitting string_PHP tutorial



PHP explode() function usage and splitting string_PHP tutorial
Jul 21, 2016 pm 03:15 PM
explode
function
php
code
function
copy
string
usage
Copy code The code is as follows:
<?
// ### Split string####
function jb51netcut($start,$end,$file){
$content=explode($start,$file);
$content=explode($end,$content[1]);
return $content[0];
}
?>
explode definition and usage
explode() function splits a string is an array.
Syntax
explode(separator,string,limit)
参数 | 描述 |
---|---|
separator | 必需。规定在哪里分割字符串。 |
string | 必需。要分割的字符串。 |
limit | 可选。规定所返回的数组元素的最大数目。 |
Explanation
This function returns an array composed of strings, each element of which is a substring separated by separator as a boundary point.
separator parameter cannot be an empty string. If separator is the empty string (""), explode() returns FALSE. If separator contains a value that is not found in string, explode() returns an array containing a single element from string.
If the limit parameter is set, the returned array contains at most limit elements, and the last element will contain the remainder of the string.
If the limit parameter is negative, all but the last -limit elements are returned. This feature is new in PHP 5.1.0.
Tips and Notes
Note: The parameter limit was added in PHP 4.0.1.
Note: 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.
Example
In this example, we will split the string into an array:
Copy code The code is as follows:
<?php
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
?> ;
Output:
Array
(
[0] => Hello
[1] => world.
[2] => It's
[3] => a
[4] => beautiful
[5] => day.
)
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
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

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
