Home > Article > Backend Development > How to remove the last few digits of a string in php
In PHP, you can use the substr function to remove the last few digits of a string. The implementation code statement is such as "echo substr("Hello world",0,5)".
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
How to remove the last few digits of a string in php ?
In PHP, you can use the substr function to remove the last few digits of a string.
The substr() function returns a part of a string.
Note: If the start parameter is a negative number and length is less than or equal to start, length is 0.
Example:
Use start and length parameters with different positive and negative numbers:
<?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>"; ?>
Running results:
Hello worl ello wor Hello world Hello worl ello wor Hello world
Recommended learning: "PHP video tutorial》
The above is the detailed content of How to remove the last few digits of a string in php. For more information, please follow other related articles on the PHP Chinese website!