PHP substr () function parameter description and usage examples, substr parameter description _php Tutorial

Source: Internet
Author: User
Tags php programming

PHP substr () function parameter description and usage example, substr parameter description


The examples in this paper describe the substr () function parameter description and usage in PHP. Share to everyone for your reference. Specific as follows:

String substr (string $string, int $start [, int $length]), which can be used to find a matching string or character in a longer string, $string the string to be processed, $start the position to start the selection, $length is the length to select.

$length read characters from left to right for positive data.

When the $length is negative, the characters are read right-to-left.

String required, which specifies the strings to return a portion of.

Start is required to specify where the string begins.

Charlist Optional, which specifies the length of the string to return, by default until the end of the string.

Positive number-starts at the specified position in the string

Negative number-starts at the specified position from the end of the string

0-Starts at the first character in a string

The PHP instance code is as follows:
Copy the Code code as follows: $rest _1 = substr ("abcdef", 2); Returns "Cdef"
$rest _2 = substr ("ABCdef",-2); Returns "EF"

$rest 1 = substr ("abcdef", 0, 0); Returns ""
$rest 2 = substr ("abcdef", 0, 2); Returns "AB"
$rest 3 = substr ("abcdef", 0,-1); Returns "ABCDE"
$rest 4 = substr ("abcdef", 2,0); Returns ""
$rest 5 = substr ("abcdef", 2,2); Returns "CD"
$rest 6 = substr ("ABCdef", 2,-1); Returns "CDE"
$rest 7 = substr ("abcdef", -2,0); Returns ""
$rest 8 = substr ("abcdef", -2,2); Returns "EF"
$rest 9 = substr ("abcdef", -2,-1); Returns "E"

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/912290.html www.bkjia.com true http://www.bkjia.com/PHPjc/912290.html techarticle php substr () function parameter description and usage examples, substr parameter description This article describes the substr () function parameter description and usage in PHP. Share to everyone for your reference. Specific as follows: ...

  • Related Article

    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.