SUBSTR () function in PHP and explode () function Usage Example

Source: Internet
Author: User
This article mainly introduces PHP substr () and explode () function usage analysis, in the form of an instance of the substr () and explode () function to deal with the string of skills, is the use of high frequency function in string operation, has a certain practical value, A friend you need can refer to the following

This example describes the use of substr () and explode () functions in PHP. Share to everyone for your reference. Here's how:

SUBSTR (string,start,length): This function takes the string string of the beginning of the strings to remove the length of a character, if start is negative, then from the end of the string, if the parameters can be omitted length exists, but is negative, To the last length of the string, the instance code is as follows:

The code is as follows:

<?php echo substr ("abcdef", 1, 3);  Returns "BCD" Echo substr ("ABCdef",-2);    Returns "EF" Echo substr ("ABCdef",-3, 1); Returns "D" Echo substr ("abcdef", 1,-1); Return to "BCDE"?>

Explode (separator,string,limit): This function splits a string into an array separator specify where to split the string to be split, the limit is optional, the maximum number of array elements, the instance code is as follows:

The code is as follows:

<?php $str = "Abc|bck|fhq|nui";    Print (Explode ("|", $SRT)); Output array ([0]=>abc,[1]=>bck,[2]=>fhq,[3]=>nui)?>

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.