PHP substr function: Returns the substring of a string.
php substr() function syntax
Function: intercept string
Syntax:
substr(string,start,length)
Parameters:
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 - starts at the first character in the string.
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.
Description: Return part of the string. If the start parameter is negative and length is less than or equal to start, length is 0.
php substr() function usage example 1:
<?php echo substr("Hello world",6); ?>
Output:
world
php substr() function usage example 2:
<?php $i = "i'm study in php.cn"; echo substr($i,8); ?>
Output:
y in php.cn
This article is an introduction to the PHP substr function. I hope it will be helpful to friends in need!
The above is the detailed content of How to use substr function. For more information, please follow other related articles on the PHP Chinese website!