Home > Backend Development > PHP Tutorial > PHPsubstr function string interception usage analysis

PHPsubstr function string interception usage analysis

小云云
Release: 2023-03-17 10:48:01
Original
1739 people have browsed it

php substr is a functional function developed based on the php language that can return a part of a string. The example in this article describes the usage of substr function string interception in PHP. Share it with everyone for your reference, the details are as follows:

The substr function in PHP is defined as follows:

substr(string,start,length)
Copy after login

The parameter description is as follows:

string required. Specifies a part of the string to be returned.

start

Required. Specifies where in the string to begin.

Positive number - starts at the specified position in the string

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

0 - first in the string Starts at character

length

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

Positive number - the length returned from the position of the start parameter

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);
//原样输出,不截取  echo "<br>";  echo substr("Welcome to www.php.cn!",4,14); 
//从第4个字符开始连续截取14个字符  echo "<br>";  echo substr("Welcome to www.php.cn!",-4,4);
//从倒数第4个开始截取4个字符  echo "<br>";  echo substr("Welcome to www.php.cn!",0,-4); 
//从第一个字符开始截取,截取到倒数第4个字符 ?>
Copy after login

The running results are as follows:

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

Although the article is very short, it can teach You have a knowledge point, I hope this article will be helpful to everyone in PHP programming.

The method of substr_count() function in PHP to obtain the number of occurrences of a substring, phpsubstr_count_PHP tutorial

Usage analysis of substr function string interception in PHP, phpsubstr

The method of substr_count() function in PHP to obtain the number of occurrences of a substring, phpsubstr_count

The above is the detailed content of PHPsubstr function string interception usage analysis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template