Extracting Substrings

You want to extract part of a string, starting at a particular place in the string. For example, you want the first eight characters of a username entered into a form.

 Extracting a substring with substr( )

<?php
$substring = substr($string,$start,$length);
$username = substr($_GET['username'],0,8);
?>
 
If $start and $length are positive, substr( ) returns 
$length characters in the string, starting at $start.
 
If $start is bigger than the length of the string, substr( ) returns false..