How to use php explode function

藏色散人
Release: 2023-04-05 06:14:02
Original
5268 people have browsed it

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)
Copy after login

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));
?>
Copy after login

Output:

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

php explode() function usage example 2:

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

Output:

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

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!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template