Home >Backend Development >PHP Problem >How to intercept the middle digits of a string in php

How to intercept the middle digits of a string in php

王林
王林Original
2021-06-25 13:37:353535browse

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);].

How to intercept the middle digits of a string in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn