PHP string Split function split

Source: Internet
Author: User

Description

array Split (string $pattern , string $string [, int $limit ])

This function returns an array of strings, each of which is a string with a case-sensitive regular expression pattern as a substring of the boundary. If limitis set, the returned array contains a maximum of limit cells, and the last cell contains all the remaining parts of the string . If there is an error, split () returns FALSE.

Example #1 Split () Example

<?php
list ( $user ,&NBSP; $pass ,&NBSP; $uid ,  $gid ,&NBSP; $extra      SPLIT&NBSP; ( ,  $passwd _line ,&NBSP; 5 );
?>

If there are n items in a string that match pattern , the returned array will contain n+1 cells. For example, if patternis not found, an array with only one cell is returned. Of course, this is true if the string is empty.


Example #2 Split () Example

<?php
//delimiter can be a slash, dot, or horizontal line
$date= "04/30/1973";
List ($month, $day, $year) = Split(' [/.-] ', $date);
Echo"Month:$month; Day:$day; Year:$year<br/> ";
?>


Note that pattern is a regular expression. If you want to use a split character that is a special character in a regular expression, first escape it.


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.