How To – Remove Leading Zeros
Solutions
Using PHP function intval().
Code example: echo intval(“05″);
Returned value: 5
Using PHP function ltrim().
Code example: echo ltrim(“005″,”0″);
Returned value: 5
Using PHP function intval().
Code example: echo intval(“05″);
Returned value: 5
Using PHP function ltrim().
Code example: echo ltrim(“005″,”0″);
Returned value: 5
26 queries. 0.349 seconds.
Copyright © 2004 - 2005 by Adam Douglas
And, just because it’s tagged PHP/MySQL…
mysql> SELECT TRIM( LEADING 0 FROM 00124000 );
+———————————+
| TRIM( LEADING 0 FROM 00124000 ) |
+———————————+
| 124000 |
+———————————+
1 row in set (0.00 sec)
You could also use a cast: (int)$str
Good points to make Joe and Toby, thanks.