Re: [PHP] variable type - conversion/checking

2013-03-18 Thread Samuel Lopes Grigolato
Sorry if I'm missing something, there's a lot of replies after my first post on this thread. Is there something wrong with the floor() approach? I liked the regex solution but isn't it more expensive and more verbose than just doing a well commented is_numeric plus floor/ceil math? Just trying

Re: [PHP] variable type - conversion/checking

2013-03-17 Thread Maciek Sokolewicz
On 16-3-2013 19:20, Matijn Woudt wrote: On Sat, Mar 16, 2013 at 6:52 PM, Maciek Sokolewicz maciek.sokolew...@gmail.com wrote: Hi, I have tried to find a way to check if a character string is possible to test whether it is convertible to an intger ! any suggestion ? BR georg All

Re: [PHP] variable type - conversion/checking

2013-03-17 Thread Matijn Woudt
On Sun, Mar 17, 2013 at 10:20 PM, Maciek Sokolewicz maciek.sokolew...@gmail.com wrote: On 16-3-2013 19:20, Matijn Woudt wrote: On Sat, Mar 16, 2013 at 6:52 PM, Maciek Sokolewicz maciek.sokolew...@gmail.com wrote: Hi, I have tried to find a way to check if a character string is

Re: [PHP] variable type - conversion/checking

2013-03-16 Thread tamouse mailing lists
On Fri, Mar 15, 2013 at 8:34 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Thu, Mar 14, 2013 at 7:02 PM, georggeorg.chamb...@telia.com** I have tried to find a way to check if a character string is possible to test whether it is convertible to an intger ! The op wasn't about

Re: [PHP] variable type - conversion/checking

2013-03-16 Thread Ashley Sheridan
On Fri, 2013-03-15 at 22:32 -0400, Andrew Ballard wrote: Guess regex are the only useful solution here. When you consider to use built-in functions, just remember, that for example '0xAF' is an integer too, but '42.00' isn't. Shoot...I hadn't considered how PHP might handle hex or octal

Re: [PHP] variable type - conversion/checking

2013-03-16 Thread Andrew Ballard
On Mar 16, 2013 6:14 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2013-03-15 at 22:32 -0400, Andrew Ballard wrote: Guess regex are the only useful solution here. When you consider to use built-in functions, just remember, that for example '0xAF' is an integer too, but

Re: [PHP] variable type - conversion/checking

2013-03-16 Thread Ashley Sheridan
On Sat, 2013-03-16 at 11:46 -0400, Andrew Ballard wrote: On Mar 16, 2013 6:14 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2013-03-15 at 22:32 -0400, Andrew Ballard wrote: Guess regex are the only useful solution here. When you consider to use built-in functions, just

Re: [PHP] variable type - conversion/checking

2013-03-16 Thread Maciek Sokolewicz
Hi, I have tried to find a way to check if a character string is possible to test whether it is convertible to an intger ! any suggestion ? BR georg All responses in this thread have been very nice; but you could also try a much simpler 2-step check: 1. is_numeric 2. if true check if

Re: [PHP] variable type - conversion/checking

2013-03-16 Thread Matijn Woudt
On Sat, Mar 16, 2013 at 6:52 PM, Maciek Sokolewicz maciek.sokolew...@gmail.com wrote: Hi, I have tried to find a way to check if a character string is possible to test whether it is convertible to an intger ! any suggestion ? BR georg All responses in this thread have been very nice;

Re: [PHP] variable type - conversion/checking

2013-03-16 Thread Andrew Ballard
On Sat, Mar 16, 2013 at 12:21 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Sat, 2013-03-16 at 11:46 -0400, Andrew Ballard wrote: On Mar 16, 2013 6:14 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2013-03-15 at 22:32 -0400, Andrew Ballard wrote: Guess regex

Re: [PHP] variable type - conversion/checking

2013-03-15 Thread Jim Lucas
On 3/14/2013 4:05 PM, Matijn Woudt wrote: On Thu, Mar 14, 2013 at 11:44 PM, Jim Lucas li...@cmsws.com wrote: On 03/14/2013 11:50 AM, Samuel Lopes Grigolato wrote: Something like if (is_numeric($var) $var == floor($var)) will do the trick. I don't know if there's a better (more elegant)

Re: [PHP] variable type - conversion/checking

2013-03-15 Thread Peter Ford
On 15/03/13 06:21, Jim Lucas wrote: On 3/14/2013 4:05 PM, Matijn Woudt wrote: On Thu, Mar 14, 2013 at 11:44 PM, Jim Lucas li...@cmsws.com wrote: On 03/14/2013 11:50 AM, Samuel Lopes Grigolato wrote: Something like if (is_numeric($var) $var == floor($var)) will do the trick. I don't know if

Re: [PHP] variable type - conversion/checking

2013-03-15 Thread Ashley Sheridan
On Fri, 2013-03-15 at 04:57 -0500, tamouse mailing lists wrote: On Fri, Mar 15, 2013 at 3:55 AM, Peter Ford p...@justcroft.com wrote: On 15/03/13 06:21, Jim Lucas wrote: On 3/14/2013 4:05 PM, Matijn Woudt wrote: On Thu, Mar 14, 2013 at 11:44 PM, Jim Lucas li...@cmsws.com wrote: On

Re: [PHP] variable type - conversion/checking

2013-03-15 Thread richard gray
On 15/03/2013 22:00, Ashley Sheridan wrote: On Fri, 2013-03-15 at 04:57 -0500, tamouse mailing lists wrote: For my money, `is_numeric()` does just what I want. The thing is, is_numeric() will not check if a string is a valid int, but any valid number, including a float. For something like

Re: [PHP] variable type - conversion/checking

2013-03-15 Thread Jim Lucas
On 03/15/2013 02:33 PM, richard gray wrote: On 15/03/2013 22:00, Ashley Sheridan wrote: On Fri, 2013-03-15 at 04:57 -0500, tamouse mailing lists wrote: For my money, `is_numeric()` does just what I want. The thing is, is_numeric() will not check if a string is a valid int, but any valid

Re: [PHP] variable type - conversion/checking

2013-03-15 Thread tamouse mailing lists
On Fri, Mar 15, 2013 at 4:00 PM, Ashley Sheridan a...@ashleysheridan.co.ukwrote: ** On Fri, 2013-03-15 at 04:57 -0500, tamouse mailing lists wrote: On Fri, Mar 15, 2013 at 3:55 AM, Peter Ford p...@justcroft.com wrote: On 15/03/13 06:21, Jim Lucas wrote: On 3/14/2013 4:05 PM, Matijn

Re: [PHP] variable type - conversion/checking

2013-03-15 Thread Ashley Sheridan
tamouse mailing lists tamouse.li...@gmail.com wrote: On Fri, Mar 15, 2013 at 4:00 PM, Ashley Sheridan a...@ashleysheridan.co.ukwrote: ** On Fri, 2013-03-15 at 04:57 -0500, tamouse mailing lists wrote: On Fri, Mar 15, 2013 at 3:55 AM, Peter Ford p...@justcroft.com wrote: On 15/03/13

Re: [PHP] variable type - conversion/checking

2013-03-15 Thread Andrew Ballard
I suppose one could try something like this: if (is_string($val) $val === (string)(int)$val) If $val is an integer masquerading as a string, it should be identical to the original string when cast back to a string, shouldn't it? (I can't try it right now.) Andrew

Re: [PHP] variable type - conversion/checking

2013-03-15 Thread Sebastian Krebs
2013/3/16 Ashley Sheridan a...@ashleysheridan.co.uk tamouse mailing lists tamouse.li...@gmail.com wrote: On Fri, Mar 15, 2013 at 4:00 PM, Ashley Sheridan a...@ashleysheridan.co.ukwrote: ** On Fri, 2013-03-15 at 04:57 -0500, tamouse mailing lists wrote: On Fri, Mar 15, 2013 at 3:55

Re: [PHP] variable type - conversion/checking

2013-03-15 Thread Sebastian Krebs
2013/3/16 Andrew Ballard aball...@gmail.com I suppose one could try something like this: if (is_string($val) $val === (string)(int)$val) If $val is an integer masquerading as a string, it should be identical to the original string when cast back to a string, shouldn't it? (I can't try

Re: [PHP] variable type - conversion/checking

2013-03-15 Thread Andrew Ballard
On Mar 15, 2013 9:54 PM, Sebastian Krebs krebs@gmail.com wrote: 2013/3/16 Andrew Ballard aball...@gmail.com I suppose one could try something like this: if (is_string($val) $val === (string)(int)$val) If $val is an integer masquerading as a string, it should be identical to the

Re: [PHP] variable type - conversion/checking

2013-03-15 Thread Andrew Ballard
Guess regex are the only useful solution here. When you consider to use built-in functions, just remember, that for example '0xAF' is an integer too, but '42.00' isn't. Shoot...I hadn't considered how PHP might handle hex or octal strings when casting to int. (Again, not in front of a computer

Re: [PHP] variable type - conversion/checking

2013-03-15 Thread Matijn Woudt
On Sat, Mar 16, 2013 at 2:54 AM, Sebastian Krebs krebs@gmail.comwrote: 2013/3/16 Andrew Ballard aball...@gmail.com I suppose one could try something like this: if (is_string($val) $val === (string)(int)$val) If $val is an integer masquerading as a string, it should be

[PHP] variable type - conversion/checking

2013-03-14 Thread georg
Hi, I have tried to find a way to check if a character string is possible to test whether it is convertible to an intger ! any suggestion ? BR georg

Re: [PHP] variable type - conversion/checking

2013-03-14 Thread Matijn Woudt
On Thu, Mar 14, 2013 at 7:02 PM, georg georg.chamb...@telia.com wrote: Hi, I have tried to find a way to check if a character string is possible to test whether it is convertible to an intger ! any suggestion ? BR georg You could use is_numeric for that, though it also accepts floats.

Re: [PHP] variable type - conversion/checking

2013-03-14 Thread Samuel Lopes Grigolato
Something like if (is_numeric($var) $var == floor($var)) will do the trick. I don't know if there's a better (more elegant) way. On Thu, Mar 14, 2013 at 3:09 PM, Matijn Woudt tijn...@gmail.com wrote: On Thu, Mar 14, 2013 at 7:02 PM, georg georg.chamb...@telia.com wrote: Hi, I have

Re: [PHP] variable type - conversion/checking

2013-03-14 Thread Jim Lucas
On 03/14/2013 11:50 AM, Samuel Lopes Grigolato wrote: Something like if (is_numeric($var) $var == floor($var)) will do the trick. I don't know if there's a better (more elegant) way. On Thu, Mar 14, 2013 at 3:09 PM, Matijn Woudttijn...@gmail.com wrote: On Thu, Mar 14, 2013 at 7:02 PM,

Re: [PHP] variable type - conversion/checking

2013-03-14 Thread Matijn Woudt
On Thu, Mar 14, 2013 at 11:44 PM, Jim Lucas li...@cmsws.com wrote: On 03/14/2013 11:50 AM, Samuel Lopes Grigolato wrote: Something like if (is_numeric($var) $var == floor($var)) will do the trick. I don't know if there's a better (more elegant) way. On Thu, Mar 14, 2013 at 3:09 PM,