Home >Backend Development >PHP Problem >How to get the number of string in php

How to get the number of string in php

王林
王林Original
2021-06-24 17:19:252425browse

The way PHP retrieves the number of a string is to pass the string as a parameter to the substr function, and set the starting point and the length of the string to be returned, for example [substr("Hello world", 6)].

How to get the number of string in php

The operating environment of this article: windows10 system, php 7.3, thinkpad t480 computer.

php has a very rich function library, including a function substr(), which can take out any part of the string. Returns FALSE on failure, or an empty string.

Syntax:

substr(string,start,length)

Parameters:

  • 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 result:

world

Related video sharing: php video tutorial

The above is the detailed content of How to get the number of 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