what does substr mean in php

WBOY
Release: 2023-03-16 13:50:02
Original
4762 people have browsed it

substr means "intercepting a string" in PHP; the substr() function can return a part of the string, the syntax is "substr(string,start,length)", and the parameter string indicates that a part of it is to be returned string, the parameter start is used to specify where the string to be intercepted starts, and the parameter length indicates the length to be intercepted.

what does substr mean in php

The operating environment of this article: Windows 10 system, PHP version 8.1, Dell G3 computer

substr function

substr() The function returns a portion of a string.

Note: If the start parameter is negative and length is less than or equal to start, length is 0.

Syntax

substr(string,start,length)
Copy after login

Parameter Description

  • string Required. Specifies a part of the string to be returned.

  • start Required. Specifies where in the string to begin.

Positive number - starts at the specified position in the string

Negative number - starts at the specified position from the end of the string

0 - starts at the specified position in the string Starts at the first character in

  • #length optional. Specifies the length of the string to be returned. The default is until the end of the string.

Positive number - Return from the position of the start parameter

Negative number - Return from the end of the string

Returned result:

Returns the extracted part of the string, returns FALSE if it fails, or returns an empty string.

The example is as follows:

<?php
// Positive numbers:
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 "<br>";
// Negative numbers:
echo substr("Hello world",-1)."<br>";
echo substr("Hello world",-10)."<br>";
echo substr("Hello world",-8)."<br>";
echo substr("Hello world",-4)."<br>";
?>
Copy after login

Output result:

what does substr mean in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of what does substr mean in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!