The function of the substr function in PHP is to return a part of the string. Its syntax is "substr(string,start,length)". Its parameter string indicates that part of the string is returned, and the parameter start indicates that it is in the string. Where to start, the parameter length indicates the interception length.
Usage examples
"; echo substr("Hello world",1)."
"; echo substr("Hello world",3)."
"; echo substr("Hello world",7)."
"; echo substr("Hello world",-1)."
"; echo substr("Hello world",-10)."
"; echo substr("Hello world",-8)."
"; echo substr("Hello world",-4)."
"; ?>
"; echo substr("Hello world",1,8)."
"; echo substr("Hello world",0,5)."
"; echo substr("Hello world",6,6)."
"; echo substr("Hello world",0,-1)."
"; echo substr("Hello world",-10,-2)."
"; echo substr("Hello world",0,-6)."
"; echo substr("Hello world",-2-3)."
"; ?>
Recommended tutorial: "PHP"
The above is the detailed content of How to use substr function in PHP?. For more information, please follow other related articles on the PHP Chinese website!