Home > Backend Development > PHP Tutorial > How to use substr function

How to use substr function

藏色散人
Release: 2023-04-05 06:20:01
Original
4137 people have browsed it

PHP substr function: Returns the substring of a string.

How to use substr function

php substr() function syntax

Function: intercept string

Syntax:

substr(string,start,length)
Copy after login

Parameters:

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 first character in the string.

length Optional. Specifies the length of the returned string. The default is until the end of the string. Positive number - the length returned from the position of the start parameter, negative number - the length returned from the end of the string.

Description: Return part of the string. If the start parameter is negative and length is less than or equal to start, length is 0.

php substr() function usage example 1:

<?php
echo substr("Hello world",6);
?>
Copy after login

Output:

world
Copy after login

php substr() function usage example 2:

<?php
$i = "i&#39;m study in php.cn";
echo substr($i,8);
?>
Copy after login

Output:

y in php.cn
Copy after login

This article is an introduction to the PHP substr function. I hope it will be helpful to friends in need!

The above is the detailed content of How to use substr function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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