The substr() function returns a part of a string.
Note: If the start parameter is a negative number and length is less than or equal to start, length becomes 0.
| Parameter | Description |
|---|---|
| string | Required. Specifies the string to return a part of |
| start | Required. Specifies where to start in the string
|
| length | Optional. Specifies the length of the returned string.
Default is to the end of the string.
|
| Return Value: | Returns the extracted part of a string, or FALSE on failure, or an empty string |
|---|---|
| PHP Version: | 4+ |
| Changelog: | In PHP Version 5.2.2 to 5.2.6, if the start parameter indicates the position of a negative truncation or beyond, FALSE is returned. Other versions get the string from start |
Using the start parameter with different positive and negative numbers:
Using the start and length parameters with different positive and negative numbers:
Complete PHP String Reference
The perfect solution for professionals who need to balance work, family, and career building.
More than 10 000 certificates already issued!
The HTML Certificate documents your knowledge of HTML.
The HTML5 Certificate documents your knowledge of advanced HTML5.
The CSS Certificate documents your knowledge of advanced CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The jQuery Certificate documents your knowledge of jQuery.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
Your message has been sent to W3Schools.