Usage of substr() function in php: The substr() function is used to return a part of a string. Function syntax: [substr(string, start, length)], where the parameter length is optional and is used to specify the length of the string to be returned.
#The substr() function is used to return a part of a string.
(Recommended tutorial: php graphic tutorial)
Function syntax:
substr(string,start,length)
Parameter introduction:
string Required. Specifies a part of the string to be returned.
#start Required. Specifies where in the string to begin.
Positive numbers - Start at the specified position in the string
Negative numbers - Start at the specified position from the end of the string
0 - Start at the specified position in the string Starts at the first character in
length Optional. Specifies the length of the string to be returned. The default is until the end of the string.
Positive number - Return from the position of the start parameter
Negative number - Return from the end of the string
(Learning video recommendation: php Video Tutorial )
Code Example:
Example 1:
<?php echo substr("Hello world!",6); ?>
Output:
world!
Example 2:
<?php echo substr("Hello world!",6,5); ?>
Output:
world
The above is the detailed content of What is the usage of substr() function in php. For more information, please follow other related articles on the PHP Chinese website!