Using the PHP split () function to explain _php skills

Source: Internet
Author: User
Tags expression engine knowledge base
The basic syntax for the PHP function split () is: Array split (String $pattern, string $string [, int $limit]). We give you two examples to illustrate the use of this function.

For beginners, mastering the usage of common functions in PHP is the basis of their continued learning. Today we will give you a detailed introduction of PHP function split () Some of the use of methods, I hope you will be able to introduce the content of this article to increase their knowledge base.
description
array Split (string $pattern, string $string [, int $limit])
Tips
The Preg_split () function uses Perl-compatible regular expression syntax, which is usually a faster alternative than the PHP function split (). If you do not need the power of regular expressions, use explode () faster, so that you do not incur the waste of the regular expression engine.
This function returns an array of strings, each of which is a substring of string separated by the case-sensitive regular expression pattern. If limit is set, the returned array contains up to limit cells, and the last cell contains all the remaining parts of the string. If an error occurs, the split () returns FALSE.
Split the first four fields in the/etc/passwd:
example 1839. php function split () example
In-depth PHP nl2br () formatted output of the detailed
Copy Code code as follows:

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

If there are n items in the string that match pattern, the returned array will contain n+1 cells. For example, if pattern is not found, an array with only one cell is returned. Of course, this is true if the string is empty.
Resolves a date that may be split by Slash, Dot, or horizontal line:
Example 1840. php function split () example
Copy Code code as follows:

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

To emulate a similar @chars in Perl = Split (", $str) behavior, refer to the example in the Preg_split () or Str_split () function.
Note that pattern is a regular expression. If you want to use a split character that is a special character in a regular expression, you must first escape it. If you think the PHP function split () (or any other Regex function) behaves strangely, read the regex.7 file contained in the regex/subdirectory of the PHP release package. This file is a manual page format that can be read with commands like man/usr/local/src/regex/regex.7

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.