...

View Full Version : Substr from the right



tomharto
09-04-2011, 11:12 PM
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

Thanks

Inigoesdr
09-04-2011, 11:19 PM
echo substr('abcd123456.jpg', -10);

tomharto
09-04-2011, 11:19 PM
Ahh, a lot simpler than i thought, i thought i need both start and length params, thankyou :)

kbluhm
09-05-2011, 02: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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum