Explode function usage analysis _php techniques in PHP

Source: Internet
Author: User
Tags explode

This article analyzes the usage of explode function in PHP. Share to everyone for your reference. Specifically as follows:

Explode (string separator,string string [, int limit])

Separator is an empty string (""), Explode () returns FALSE, and if separator contains a value that is not found in string, explode () returns an array containing a single element of string.

Explode instance one, the code is as follows:

Copy Code code as follows:
$explode = "AAA,BBB,CCC,DDD,EXPLODE,JJJJ";

$array = Explode (', ', $explode);

Print_r ($array);
/*
Result is
Array
(
[0] => AAA
[1] => BBB
[2] => CCC
[3] => DDD
[4] => explode
[5] => JJJJ
)
*/

We can use the explode function with the End function when we process the date or get the file name extension, the following example, the code is as follows:
Copy Code code as follows:
$file = "Www.jb51.net.gif";

$extArray = Explode ('. ', $file);
$ext = End ($extArray);
Echo $ext;

The output value is. gif

Some of the error prompts that appear with some functions are: Note:separator cannot be a empty string. Note: The delimiter cannot be a null string, and the string to be split is empty.

The Definition and Usage do not use a split function, possibly the split character you set does not exist.

I hope this article will help you with your PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.