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
<?php echo substr("Hello world",10)."<br>"; echo substr("Hello world",1)."<br>"; echo substr("Hello world",3)."<br>"; echo substr("Hello world",7)."<br>"; echo substr("Hello world",-1)."<br>"; echo substr("Hello world",-10)."<br>"; echo substr("Hello world",-8)."<br>"; echo substr("Hello world",-4)."<br>"; ?>
<?php echo substr("Hello world",0,10)."<br>"; echo substr("Hello world",1,8)."<br>"; echo substr("Hello world",0,5)."<br>"; echo substr("Hello world",6,6)."<br>"; echo substr("Hello world",0,-1)."<br>"; echo substr("Hello world",-10,-2)."<br>"; echo substr("Hello world",0,-6)."<br>"; echo substr("Hello world",-2-3)."<br>"; ?>
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!