Home >Backend Development >PHP Problem >How to intercept the middle digits of a string in php
The way PHP intercepts the middle digits of a string is to pass the string as a parameter to the substr function, and set where the string starts and the length of the string to be returned, for example [substr( "Hello world",6);].
The operating environment of this article: windows10 system, php 7.3, thinkpad t480 computer.
In PHP we usually use the substr function to intercept a string. This function will return the extracted part of the string. If it fails, it will return FALSE or an empty string. Below we briefly introduce the substr 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.
#length Optional. Specifies the length of the string to be returned. The default is until the end of the string.
Code example:
<!DOCTYPE html> <html> <body> <?php echo substr("Hello world",6); ?> </body> </html>
Running results:
world
Related learning video sharing: php video tutorial
The above is the detailed content of How to intercept the middle digits of a string in php. For more information, please follow other related articles on the PHP Chinese website!