JSHINER Posted September 9, 2008 Share Posted September 9, 2008 I have something that pulls from the database "001904" - but I need those leading zeros gone when echoed, but need them there when in the database. Obviously str_replace() won't work because it will get rid of zeros in between numbers. How can I do this? Link to comment https://forums.phpfreaks.com/topic/123525-getting-rid-of-leading-zeros/ Share on other sites More sharing options...
lisa71283 Posted September 9, 2008 Share Posted September 9, 2008 Cast the result as an integer. Link to comment https://forums.phpfreaks.com/topic/123525-getting-rid-of-leading-zeros/#findComment-637924 Share on other sites More sharing options...
sasa Posted September 9, 2008 Share Posted September 9, 2008 look <?php $a = '001020.300'; echo $a + 0; ?> Link to comment https://forums.phpfreaks.com/topic/123525-getting-rid-of-leading-zeros/#findComment-637939 Share on other sites More sharing options...
gbunny Posted September 9, 2008 Share Posted September 9, 2008 If you don't want to cast it as an int you could use the ltrim function. It would look something like this. <? $newString = ltrim($yourString, "0"); ?> You can find the documentation here http://www.php.net/manual/en/function.ltrim.php Link to comment https://forums.phpfreaks.com/topic/123525-getting-rid-of-leading-zeros/#findComment-637963 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.