Binary Expressions

2008-10-7

How To – Remove Leading Zeros

Filed under: — Adam @ 11:49 am

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

3 Responses to “How To – Remove Leading Zeros”

  1. Joe Izenman says:

    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)

  2. Toby says:

    You could also use a cast: (int)$str

  3. Adam says:

    Good points to make Joe and Toby, thanks.

Leave a Reply

Take back your mailbox - CAUCE.org

Powered By Wordpress PHP: Hypertext Preprocessor MySQL Powered Download Juice, the cross-platform podcast receiver
Proud To Be Canadian Get Firefox Valid XHTML Valid CSS
<NO>OOXML Logo


26 queries. 0.349 seconds.
Copyright © 2004 - 2005 by Adam Douglas