Files
freeCodeCamp/mock-guide/english/php/substring/index.md
Joe Erickson 0890dda962 Add content for PHP strings (#27489)
* Add content for PHP strings

* fix: resolved conflict
2019-02-28 16:37:12 -08:00

839 B

title
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