Home  >  Article  >  Backend Development  >  How to use php explode function

How to use php explode function

藏色散人
藏色散人Original
2019-02-01 10:08:015289browse

PHP explode function is used to use one string to split another string. Its syntax is explode(separator, string, limit). The parameter separator is required, which refers to where to split the string; string is required, which refers to the characters to be split. string.

How to use php explode function

How to use php explode function?

php explode() function syntax

Function: string Scattered into an array

Syntax:

explode(separator,string,limit)

Parameters:

separator Required. Specifies where to split the string.

string Required. The string to split.

limit Optional. Specifies the number of array elements to be returned. Possible values: greater than 0 - returns an array containing at most limit elements, less than 0 - returns an array containing all but the last -limit elements, 0 - returns an array containing one element

Instructions:

Break up the string into an array. The "separator" parameter cannot be an empty string. This function is binary safe.

php explode() function usage example 1:

<?php
$str = "Hello world. I&#39;m study in php.cn!";
print_r (explode(".",$str));
?>

Output:

Array ( [0] => Hello world [1] => I&#39;m study in php [2] => cn! )

php explode() function usage example 2:

<?php
$arr = "Learning PHP is a good choice";
print_r(explode(" ", $arr));
?>

Output:

Array ( [0] => Learning [1] => PHP [2] => is [3] => a [4] => good [5] => choice )

This article is an introduction to the PHP explode function. I hope it will be helpful to friends in need!

The above is the detailed content of How to use php explode function. For more information, please follow other related articles on the PHP Chinese website!

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