Professional Web Applications Themes

check string rep's integer - PHP Development

Is there a PHP function to verify that a string validly represents an integer?...

Sponsored Links
  1. #1

    Default check string rep's integer

    Is there a PHP function to verify that a string validly represents an
    integer?


    Sponsored Links
    sinister Guest

  2. #2

    Default Re: check string rep's integer

    *** sinister wrote/escribió (Fri, 21 Nov 2003 15:10:16 GMT):
    > Is there a PHP function to verify that a string validly represents an
    > integer?
    Check is_int() manual page.

    --
    --
    -- Álvaro G. Vicario - Burgos, Spain
    --
    Alvaro G Vicario Guest

  3. #3

    Default Re: check string rep's integer

    "sinister" <sinisternospam.invalid> writes:
    > Is there a PHP function to verify that a string validly represents an
    > integer?
    See the Variable Functions chapter in the PHP manual:

    [url]http://www.php.net/manual/en/ref.variables.php[/url]

    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
    [url]http://www.fuhr.org/~mfuhr/[/url]
    Michael Fuhr Guest

  4. #4

    Default Re: check string rep's integer


    "Alvaro G Vicario" <alvaro_QUITAR_REMOVEtelecomputeronline.com> wrote in
    message news:1pg01rztodora.12za8gcvf9hnq.dlg40tude.net...
    > *** sinister wrote/escribió (Fri, 21 Nov 2003 15:10:16 GMT):
    > > Is there a PHP function to verify that a string validly represents an
    > > integer?
    >
    > Check is_int() manual page.
    No; that checks whether a variable is an integer, not whether a string
    variable corrected represents an integer.

    I'm thinking of
    "66" true
    "00037" true
    "afdfdfd" false
    "-00218" true
    "- 18" false
    >
    > --
    > --
    > -- Álvaro G. Vicario - Burgos, Spain
    > --

    sinister Guest

  5. #5

    Default Re: check string rep's integer


    "Michael Fuhr" <mfuhrfuhr.org> wrote in message
    news:3fbe32d3_1omega.dimensional.com...
    > "sinister" <sinisternospam.invalid> writes:
    >
    > > Is there a PHP function to verify that a string validly represents an
    > > integer?
    >
    > See the Variable Functions chapter in the PHP manual:
    >
    > [url]http://www.php.net/manual/en/ref.variables.php[/url]
    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++.
    > 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
    > [url]http://www.fuhr.org/~mfuhr/[/url]

    sinister Guest

  6. #6

    Default Re: check string rep's integer

    "sinister" <sinisternospam.invalid> writes:
    > "Michael Fuhr" <mfuhrfuhr.org> wrote in message
    > news:3fbe32d3_1omega.dimensional.com...
    > > "sinister" <sinisternospam.invalid> writes:
    > >
    > > > Is there a PHP function to verify that a string validly represents an
    > > > integer?
    > >
    > > See the Variable Functions chapter in the PHP manual:
    > >
    > > [url]http://www.php.net/manual/en/ref.variables.php[/url]
    >
    > 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.
    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 doentation and user
    comments.

    --
    Michael Fuhr
    [url]http://www.fuhr.org/~mfuhr/[/url]
    Michael Fuhr Guest

  7. #7

    Default Re: check string rep's integer


    "Michael Fuhr" <mfuhrfuhr.org> wrote in message
    news:3fbebd84$1_2omega.dimensional.com...
    > "sinister" <sinisternospam.invalid> writes:
    >
    > > "Michael Fuhr" <mfuhrfuhr.org> wrote in message
    > > news:3fbe32d3_1omega.dimensional.com...
    > > > "sinister" <sinisternospam.invalid> writes:
    > > >
    > > > > Is there a PHP function to verify that a string validly represents
    an
    > > > > integer?
    > > >
    > > > See the Variable Functions chapter in the PHP manual:
    > > >
    > > > [url]http://www.php.net/manual/en/ref.variables.php[/url]
    > >
    > > 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.
    >
    > 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
    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
    > my first followup, the solution isn't as obvious as it might seem
    > at first, but it's there if you read the doentation and user
    > comments.
    >
    > --
    > Michael Fuhr
    > [url]http://www.fuhr.org/~mfuhr/[/url]

    sinister Guest

  8. #8

    Default Re: check string rep's integer

    *** sinister wrote/escribió (Fri, 21 Nov 2003 20:14:29 GMT):
    >> Check is_int() manual page.
    >
    > No; that checks whether a variable is an integer, not whether a string
    > variable corrected represents an integer.
    You are right. Probably intval() is a better choice.

    --
    --
    -- Álvaro G. Vicario - Burgos, Spain
    --
    Alvaro G Vicario Guest

Similar Threads

  1. string to integer
    By Mark Fenbers in forum Macromedia Flash Data Integration
    Replies: 10
    Last Post: May 23rd, 08:08 AM
  2. check, if a value is integer
    By Martin Nadoll in forum Macromedia ColdFusion
    Replies: 2
    Last Post: March 23rd, 06:09 PM
  3. php array problem string to integer
    By Sébastien in forum PHP Development
    Replies: 0
    Last Post: August 3rd, 06:17 AM
  4. HowTo check if my String is a Number (Integer) ?
    By Craig Deelsnyder in forum ASP.NET
    Replies: 0
    Last Post: July 27th, 11:06 PM
  5. Equating a String & Integer Variable
    By Roger Lord in forum ASP.NET General
    Replies: 2
    Last Post: July 3rd, 02:21 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139