English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP String Character String Functions Manual
The substr() function is used to return a substring of the string.
string substr ( string $string, int $start [, int $length ] )
Returns a substring of the string string specified by the start and length parameters.
It returns a part of the string
Serial Number | Parameters and Description |
---|---|
1 | string Required. Specifies the input string. It must have at least one character. |
2 | start Required. It specifies where to start in the string.
|
3 | length It specifies the length of the string to be returned. The default is to the end of the string.
|
Try the following example, returning "Krishna" from the string:
<?php //Returns "Krishna" from the string echo substr("Sairam Krishna",6).'<br>'; //Using the start parameter with different positive and negative numbers: echo substr("abcdef", 0, -1).'<br>'; // Returns "abcde" echo substr("abcdef", 2, -1).'<br>'; // Returns "cde" echo substr("abcdef", 4, -4).'<br>'; // Returns "" echo substr("abcdef", -3, -1); // Returns "de" ?>Test and see‹/›
Output Result
Krishna abcde cde de