PHP Split function

Source: Internet
Author: User

The syntax for the split function in PHP is: Array split (String $pattern, string $string [, int $limit])

The split () function returns an array of strings, each of which is a substring separated by a regular expression $pattern as a boundary $string. If $limit is set, the returned array contains up to $limit cells, and the last cell contains all the remaining parts of the $string.

Pattern: Specifies the symbol to be identified as an explosion, note that the parameter is case-sensitive.

$string: The string to be processed.

Limit: Returns the maximum number of decomposed substrings, which are returned by default.


Example
#1 Split () example

Put a string such as: "1:0:1:0:1″ into an array and then output
$str = "1:0:1:0:1″;
$arraylist =split (":", $STR); Save in Array

for ($i =0; $i <count ($arraylist); $i + +)//output them all
{
echo $arraylist [$i]. "";
}

#2 Split () example

To split off the ' the ' the ' four fields from line from/etc/passwd:

Divide the/ect/password into five parts: the first four and the last

<?php
List ($user, $pass, $uid, $gid, $extra) =
Split (":", $passwd _line, 5);
?>
#3 Split () example

To parse a date which may is delimited with slashes, dots, or hyphens:

To separate the date with a diagonal stem, dot, or horizontal line

<?php
Delimiters may be slash, dot, or hyphen
$date = "04/30/1973";
List ($month, $day, $year) = Split (' [/.-] ', $date);
echo "Month: $month; Day: $day; Year: $year <br/>\n ";
?>

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.