Files
freeCodeCamp/guide/english/php/substring/index.md
Gabriel Hoverman 9526a6ed03 Added PHP Substring Function to Guide. (#33826)
* Added PHP Substring Function to Guide.

* Added PHP Substring Function to Guide.

* Fixed typo
2019-02-20 08:40:18 -08:00

45 lines
839 B
Markdown

---
title: subtring
---
## Substring Function in PHP
The Substring function in PHP returns a portion of the string, specified by two parameters, the start and the length.
## Syntax
The substring function is used like any other function in php, and uses the subtr() syntax.
```
<?php
subtr( $string, $start, $length);
```
## Example
Below is an example of how you could use the substring function in a real world situation:
```
<?php
$apple = 'Apple';
$alphabet = 'abcdefghijklmnopqrstuvwxyz';
substr($apple, 0, 5); // Apple;
substr($apple, 0, 3); // App;
substr($apple, 3, 2); // le;
substr($alphabet, 0, 26); // abcdefghijklmnopqrstuvwxyz;
substr($alphabet, 12, 6); // mnopqr;
```
## Additional Info
For more information, please see [PHP: Substring](http://php.net/manual/en/function.substr.php)