Phpsubstr function string Interception usage analysis

Source: Internet
Author: User
PHP substr is a functional function that is developed based on the PHP language that can return a part of a string. This example describes the use of SUBSTR function string interception in PHP. Share to everyone for your reference, as follows:

The SUBSTR function in PHP is defined as follows:

SUBSTR (String,start,length)

The parameters are described as follows:

string is required. A string that specifies the part to return.

Start

Necessary. Specifies where to start the string.

Positive number-starts at the specified position in the string

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

0-Starts at the first character in a string

Length

Optional. Specifies the length of the string to be returned. The default is until the end of the string.

Positive number-length returned from the position where the start parameter is located

Negative number-The length returned from the end of the string

The sample code is as follows:

123456789 <?php  Echo substr ("Welcome to www.php.cn!", 0);//output without intercepting  echo "<br>";  echo substr ("Welcome to www.php.cn!", 4,14); 14 Characters of  echo "<br>" starting from the 4th character;  echo substr ("Welcome to www.php.cn!", -4,4);//4-character  echo "<br>" starting from the bottom of the 4th.  echo substr ("Welcome to www.php.cn!", 0,-4); Intercept from the first character and intercept to the 4th character?>

The results of the operation are as follows:

? 1234 Welcome to Www.php.cn!welcome tophp.cn! Welcome to www.php.cn.

Although the article is very brief, but can teach you a knowledge point, I hope that this article on the PHP program to help you.

PHP substr_count () function gets the number of substring occurrences, phpsubstr_count_php tutorial

substr function string interception usage analysis in PHP, PHPSUBSTR

The Substr_count () function in PHP gets the number of occurrences of substrings, Phpsubstr_count

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.