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
1$words = explode(" ", $string);
2
3$firstname = $words[0];
4$lastname = $words[1];
5$third_word = $words[2];