1
2<?php
3echo substr('abcdef', 1); // bcdef
4echo substr('abcdef', 1, 3); // bcd
5echo substr('abcdef', 0, 4); // abcd
6echo substr('abcdef', 0, 8); // abcdef
7echo substr('abcdef', -1, 1); // f
8
9// Accessing single characters in a string
10// can also be achieved using "square brackets"
11$string = 'abcdef';
12echo $string[0]; // a
13echo $string[3]; // d
14echo $string[strlen($string)-1]; // f
15
16?>
17
18//substr() function returns certain bits of a string
1substr ( $string , $start , $length );
2
3/**Returns the extracted part of string;
4 *or FALSE on failure, or an empty string
5 */
1<?php
2$str = "Africa Beautiful!";
3echo substr($str, 0, 6); // Outputs: Africa
4echo substr($str, 0, -10); // Outputs: Beautiful
5echo substr($str, 0); // Outputs: Africa Beautiful!
6?>