*** sinister wrote/escribió (Fri, 21 Nov 2003 15:10:16 GMT):[color=blue]
> Is there a PHP function to verify that a string validly represents an
> integer?[/color]
PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.
The answer may not be as simple as you'd initially think, so be
sure to read a function's description and user-contributed notes
before using it. Test whatever code you end up writing to make
sure it gives the expected results for both integers and non-integers.
You could also use a regular expression, but using variable functions
would probably make your intentions more clear.
"Alvaro G Vicario" <alvaro_QUITAR_ REMOVE@telecomp uteronline.com> wrote in
message news:1pg01rztod ora.12za8gcvf9h nq.dlg@40tude.n et...[color=blue]
> *** sinister wrote/escribió (Fri, 21 Nov 2003 15:10:16 GMT):[color=green]
> > Is there a PHP function to verify that a string validly represents an
> > integer?[/color]
>
> Check is_int() manual page.[/color]
No; that checks whether a variable is an integer, not whether a string
variable corrected represents an integer.
"Michael Fuhr" <mfuhr@fuhr.org > wrote in message
news:3fbe32d3_1 @omega.dimensio nal.com...[color=blue]
> "sinister" <sinister@nospa m.invalid> writes:
>[color=green]
> > Is there a PHP function to verify that a string validly represents an
> > integer?[/color]
>
> See the Variable Functions chapter in the PHP manual:
>
> http://www.php.net/manual/en/ref.variables.php[/color]
Not sure I understand the connection to variable functions. I would have
thought that I need a function on a string, returning a boolean, and that
either (a) it's already in php, or (b) I'd have to write my own.
I've done (b) in C and C++.
[color=blue]
> The answer may not be as simple as you'd initially think, so be
> sure to read a function's description and user-contributed notes
> before using it. Test whatever code you end up writing to make
> sure it gives the expected results for both integers and non-integers.
>
> You could also use a regular expression, but using variable functions
> would probably make your intentions more clear.
>
> --
> Michael Fuhr
> http://www.fuhr.org/~mfuhr/[/color]
"sinister" <sinister@nospa m.invalid> writes:
[color=blue]
> "Michael Fuhr" <mfuhr@fuhr.org > wrote in message
> news:3fbe32d3_1 @omega.dimensio nal.com...[color=green]
> > "sinister" <sinister@nospa m.invalid> writes:
> >[color=darkred]
> > > Is there a PHP function to verify that a string validly represents an
> > > integer?[/color]
> >
> > See the Variable Functions chapter in the PHP manual:
> >
> > http://www.php.net/manual/en/ref.variables.php[/color]
>
> Not sure I understand the connection to variable functions. I would have
> thought that I need a function on a string, returning a boolean, and that
> either (a) it's already in php, or (b) I'd have to write my own.[/color]
Did you look at the list of functions at the above link? If none
of them seem suitable, could you explain why? As I mentioned in
my first followup, the solution isn't as obvious as it might seem
at first, but it's there if you read the documentation and user
comments.
"Michael Fuhr" <mfuhr@fuhr.org > wrote in message
news:3fbebd84$1 _2@omega.dimens ional.com...[color=blue]
> "sinister" <sinister@nospa m.invalid> writes:
>[color=green]
> > "Michael Fuhr" <mfuhr@fuhr.org > wrote in message
> > news:3fbe32d3_1 @omega.dimensio nal.com...[color=darkred]
> > > "sinister" <sinister@nospa m.invalid> writes:
> > >
> > > > Is there a PHP function to verify that a string validly represents[/color][/color][/color]
an[color=blue][color=green][color=darkred]
> > > > integer?
> > >
> > > See the Variable Functions chapter in the PHP manual:
> > >
> > > http://www.php.net/manual/en/ref.variables.php[/color]
> >
> > Not sure I understand the connection to variable functions. I would[/color][/color]
have[color=blue][color=green]
> > thought that I need a function on a string, returning a boolean, and[/color][/color]
that[color=blue][color=green]
> > either (a) it's already in php, or (b) I'd have to write my own.[/color]
>
> Did you look at the list of functions at the above link? If none
> of them seem suitable, could you explain why? As I mentioned in[/color]
OK, looking at the page again, I see what you mean. Basically, it's (b)
"I'd have to write my own," but the user comments show how to make it short
and sweet.
Thanks.
Best,
S
[color=blue]
> my first followup, the solution isn't as obvious as it might seem
> at first, but it's there if you read the documentation and user
> comments.
>
> --
> Michael Fuhr
> http://www.fuhr.org/~mfuhr/[/color]
*** sinister wrote/escribió (Fri, 21 Nov 2003 20:14:29 GMT):[color=blue][color=green]
>> Check is_int() manual page.[/color]
>
> No; that checks whether a variable is an integer, not whether a string
> variable corrected represents an integer.[/color]
You are right. Probably intval() is a better choice.
Comment