Php string function learning-substr () _ PHP Tutorial

Source: Internet
Author: User
Php string function learning substr (). Php string function learning substr () This article mainly introduces php string function learning substr (), this article explains its definition and usage, Parameter descriptions, prompts and comments, and several substr () methods for learning php string functions ()

This article mainly introduces substr () in php string function Learning. This article describes its definition and usage, Parameter descriptions, prompts and comments, and multiple examples, for more information, see

/*
Definition and usage
The substr () function returns the extracted substring, or FALSE if it fails.

Syntax
Substr (string, start, length)

Parameter description
String is required. Specifies that a part of the string is to be returned.
Start
Required. Specifies where the string starts.
Non-negative-starts from the start position of the string and starts from 0.
Negative number-start from the start character at the end of string.
If the string length is less than or equal to start, FALSE is returned.

Length
Optional. Specifies the length of the string to be returned. The default value is until the end of the string.
Positive number-start from start can contain a maximum of length characters (depending on the length of string ).
Negative number-remove the length of the forward character from the end of the string
If the length is 0, FALSE, or NULL, an empty string is returned.
*/

$ Str = "abcdefghijklmn ";

$ Rest = substr ($ str, 0); // return "abcdefghijklmn"
Echo $ rest ."
";

$ Rest = substr ($ str, 1, 3); // return "bcd"
Echo $ rest ."
";

$ Rest = substr ($ str,-3); // return "lmn"
Echo $ rest ."
";

$ Rest = substr ($ str,-3, 2); // return "lm"
Echo $ rest ."
";

$ Rest = substr ($ str, 1,-3); // return "bcdefghijk"
Echo $ rest ."
";

$ Rest = substr ($ str,-7,-3); // return "hijk"
Echo $ rest ."
";
?>

This article mainly introduces the php string function learning substr (). This article explains its definition and usage, parameter description, prompts and comments, and multiple Enis...

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.