JustinK101 Posted April 30, 2011 Share Posted April 30, 2011 Discovered something very strange with trim() and numbers with leading zeros. <?php $number = 0456; echo trim($number); ?> That ouputs 302. How the heck does 0456 trimmed turn into 302? Is this a bug? Link to comment https://forums.phpfreaks.com/topic/235221-trim-with-numbers-with-leading-zeros-possible-bug/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 30, 2011 Share Posted April 30, 2011 Leading zero's on numbers make them OCTAL. Trim is a string function anyway. To get the correct results (for the example you posted), you would need to make your number into a string, either by enclosing it in quotes or casting it as a string. Edit: casting the number as a string doesn't work. Only enclosing it in quotes where you assigned it to the $number variable works. Link to comment https://forums.phpfreaks.com/topic/235221-trim-with-numbers-with-leading-zeros-possible-bug/#findComment-1208782 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.