php substr() function


  Translation results:

UK ['sʌbstər] US ['sʌbstər]

abbr.substructure substructure, underground building

php substr() functionsyntax

Function: Intercept string

Syntax: substr(string,start,length)

Parameters:

Parameter Description
stringRequired. Specifies a part of the string to be returned.
startRequired. 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: Returns part of the string. If the start parameter is negative and length is less than or equal to start, length is 0.

php substr() functionexample

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

Run instance»

Click the "Run instance" button to view the online instance

Output:

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

Run Instance»

Click the "Run Instance" button to view the online instance

Output:

y in php.cn

Home

Videos

Q&A