Is there a simple way to remove a leading zero (as in 01 becoming 1)?
Maybe it's worth putting an is_numeric() block around it to catch cases where $str is not a number, since intval returns 0 on failure: http://fr.php.net/manual/en/function.intval.php
Michael Stum
2008-12-01 15:36:08
The classic, Add-an-aritmetic-calculation-that-doesnt-change-the-original-value-to-make-the-compiler-cast-it-to-a-numeric-value-trick! ;)
Stefan
2008-12-01 15:17:43
@Jeff Atwood: I'm guessing this is a serious answer. So many PHP programmers are self-taught and know how to get the job done, not how to get it done *right*[email protected]. Fitz.Gerald: Sorry that you're being dogged. This really peeves CS people. It's not an explicit solution to the problem.
Lucas Oman
2008-12-01 15:52:33
@epochwolf - why is this not a good way to do this? I have previously advocated $str_value + 0 to convert a number-in-a-string to a number.
staticsan
2008-12-02 05:40:30
+1
A:
if you use the trim functions, you might mistakenly remove some other character, like by triming "12" your will have "2". use the intval() function. this function will convert your string (which could start by a leading zero or not) to an integer value. intval("02") will be 2 and intval ("32") wll be 32.
farzad
2008-12-01 19:25:31