Home  >  Article  >  Backend Development  >  How to use substr function

How to use substr function

藏色散人
藏色散人Original
2019-02-01 10:37:204043browse

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)

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);
?>

Output:

world

php substr() function usage example 2:

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

Output:

y in php.cn

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!

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