View Full Version : Substr from the right

09-05-2011, 12:12 AM
I need to liit the length of a value from the right, its an image so it must keep the .fileType on the end, ive looked at the manual for substr but cant get my head around the negative numbers.

How would i right it so the string is 10 letters long from the right? So if the name was

abcd123456.jpg it would return 123456.jpg


09-05-2011, 12:19 AM
echo substr('abcd123456.jpg', -10);

09-05-2011, 12:19 AM
Ahh, a lot simpler than i thought, i thought i need both start and length params, thankyou :)

09-05-2011, 03:09 AM
From http://www.php.net/substr:

If length is omitted, the substring starting from start until the end of the string will be returned.