PHP String Function Learning substr () _php Tutorial

Source: Internet
Author: User

PHP String Function Learning substr ()


This article mainly introduces the PHP string function learning substr (), this article explains its definition and usage, parameter description, hints and comments, as well as a number of use examples, the need for friends can refer to the following

/*
Definition and usage
The substr () function returns the extracted substring, or FALSE on failure.

Grammar
SUBSTR (String,start,length)

Parameter description
string is required. A string that specifies the part to return.
Start
Necessary. Specifies where to start the string.
Non-negative-starts from the start position of string and is calculated from 0.
Negative number-starts at the end of the string, starting at the start of the first character.
If the length of the string is less than or equal to start, FALSE is returned.

Length
Optional. Specifies the length of the string to return. The default is until the end of the string.
Positive number-includes a maximum of length characters (depending on the length of the string) starting at start.
Negative number-Removes the forward length character from the end of the string
If a length of value 0,false or NULL is provided, an empty string is returned.
*/

$str = "ABCDEFGHIJKLMN";

$rest = substr ($str, 0); Back to "ABCDEFGHIJKLMN"
Echo $rest. "
";

$rest = substr ($str, 1, 3); Returns "BCD"
Echo $rest. "
";

$rest = substr ($str,-3); Back to "LMN"
Echo $rest. "
";

$rest = substr ($str,-3, 2); Return to "LM"
Echo $rest. "
";

$rest = substr ($str, 1,-3); Back to "Bcdefghijk"
Echo $rest. "
";

$rest = substr ($str,-7,-3); Back to "Hijk"
Echo $rest. "
";
?>

http://www.bkjia.com/PHPjc/975118.html www.bkjia.com true http://www.bkjia.com/PHPjc/975118.html techarticle PHP String Function Learning substr () This article mainly introduces the PHP string function learning substr (), this article explains its definition and usage, parameter description, hints and comments, as well as several make ...

  • 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.