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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mccommunity
Forum Commoner
Posts: 62
Joined: Mon Oct 07, 2002 8:55 am

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

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

echo ((int)$variable);
mccommunity
Forum Commoner
Posts: 62
Joined: Mon Oct 07, 2002 8:55 am

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

$stripped_fname=ltrim($fname,"0");
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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.
Post Reply