PHP explode Function



PHP Tutorial > String Functions > explode Function

The explode function in PHP is used to split a string into multiple strings based on the specified delimiter. It is similar to the split function in Perl. Earlier versions of PHP had its own version of the split function, but it was deprecated as of PHP 5.3.0 and removed from PHP altogether as of 6.0.0. Using the split function in PHP is strongly discouraged.

The syntax of the explode function is:

explode ('delimiter', 'string', [limit])

delimiter is the string (can be one or more characters) used to split string. [limit] is an optional parameter and has the following values:

> 0: Returns an array with a maximum of limit element(s).

< 0: Returns an array except for the last -limit element(s).

0: Returns an array with 1 element.

Let's take a look at the examples below:

Example 1

print_r (explode (',','one,two,three'));

Result:

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

Example 2

$var = 'Learn PHP';
print_r (explode (' ',$var));

Result:

Array ( [0] => Learn [1] => PHP )

Example 3

print_r (explode (',','one,two,three',2));

Result:

Array ( [0] => one [1] => two,three )

Next: PHP htmlentities Function




Copyright © 2013   1keydata.com  All Rights Reserved.  Privacy Policy


PHP addslashes
PHP echo
PHP explode
PHP htmlentities
PHP htmlspecialchars
PHP implode
PHP md5
PHP number_format
PHP print
PHP str_replace
PHP strlen
PHP strpos
PHP strstr
PHP substr
PHP trim

PHP Syntax

PHP Sitemap

PHP Resources