Mega Code Archive

 
Categories / Php / Strings
 

Using negative lengths allows you to say copy everything but the last three characters

<?     $string = "Goodbye, Perl!"     $a = substr($string, 5);     $b = substr($string, 5, 5);     $c = substr($string, 0, -1);     $d = substr($string, -5);     $e = substr($string, -5, 4);     $e will be set to "Perl"     $f = substr($string, -5, -4); ?>