Page 1 of 1

Is there a function that will strip a leading 0 off a number

Posted: Tue Nov 18, 2003 11:42 am
by mccommunity
Is there a function that will strip a leading 0 off a number? For example it the number is 013 it will make it 13 I dont want to just strip the first character because it could be 113 and I want that to remail 113. Thanks for your help.


Mark

Posted: Tue Nov 18, 2003 11:45 am
by Weirdan

Code: Select all

echo ((int)$variable);

Posted: Tue Nov 18, 2003 12:03 pm
by mccommunity
Sorry I was not clear with my question the above reply would do the trick it the string was an integer but its actually an image name so 0113.jpg needs to be 113.jpg thanks, sorry for the confustion.

Posted: Tue Nov 18, 2003 12:11 pm
by Weirdan

Code: Select all

$stripped_fname=ltrim($fname,"0");

Posted: Tue Nov 18, 2003 12:12 pm
by m3mn0n
I would [php_man]explode[/php_man]() the string from the . and then convert the first half into an integer, use the code he posted, and then join the two together again.