Is there a PHP command to

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jools@by.com

    #1

    Is there a PHP command to


    Just wondering what the simplest way to sort IP addresses would be
    Is there a good way to sort that keeps them in sequence
    asort() sorts on the first character so that doesnt quite do it of course

    -jools-
  • Paul Lautman

    #2
    Re: Is there a PHP command to

    jools@by.com wrote:
    Just wondering what the simplest way to sort IP addresses would be
    Is there a good way to sort that keeps them in sequence
    asort() sorts on the first character so that doesnt quite do it of
    course
    >
    -jools-
    Did you wonder enough to type
    php sort ip addresses
    into google and then press I'm feeling lucky?

    Obviously not!


    Comment

    • Rik Wasmus

      #3
      Re: Is there a PHP command to

      On Mon, 07 Jan 2008 19:48:09 +0100, <jools@by.comwr ote:
      >
      Just wondering what the simplest way to sort IP addresses would be
      Is there a good way to sort that keeps them in sequence
      asort() sorts on the first character so that doesnt quite do it of course
      Convert them to a number (using usort())?


      --
      Rik Wasmus

      Comment

      • Michael Fesser

        #4
        Re: Is there a PHP command to

        ..oO(jools@by.c om)
        >Just wondering what the simplest way to sort IP addresses would be
        You could convert them to a long int, then use normal numeric sorting.

        Micha

        Comment

        • jools@by.com

          #5
          Re: Is there a PHP command to

          In article <5ufallF1gdopbU 1@mid.individua l.net>,
          paul.lautman@bt internet.com says...
          jools@by.com wrote:
          Just wondering what the simplest way to sort IP addresses would be
          Is there a good way to sort that keeps them in sequence
          asort() sorts on the first character so that doesnt quite do it of
          course

          -jools-
          >
          Did you wonder enough to type
          php sort ip addresses
          into google and then press I'm feeling lucky?
          >
          Obviously not!
          >
          >
          >
          All google sites are blocked in my firewall.
          I did wonder why newsgroups exist.
          I guess you could tell me if you tried?

          -jools-

          Comment

          • jools@by.com

            #6
            Re: Is there a PHP command to

            In article <op.t4kpci035bn juv@metallium.l an>, luiheidsgoeroe@ hotmail.com
            says...
            On Mon, 07 Jan 2008 19:48:09 +0100, <jools@by.comwr ote:
            >

            Just wondering what the simplest way to sort IP addresses would be
            Is there a good way to sort that keeps them in sequence
            asort() sorts on the first character so that doesnt quite do it of course
            >
            Convert them to a number (using usort())?


            --
            Rik Wasmus
            >
            Aha - I knew there had to be something that helped - thanks Rik.

            -jools-

            Comment

            • jools@by.com

              #7
              Re: Is there a PHP command to

              In article <v5t4o3t9dj002n 1irs08nuna65al0 ausbb@4ax.com>, netizen@gmx.de
              says...
              .oO(jools@by.co m)
              >
              Just wondering what the simplest way to sort IP addresses would be
              >
              You could convert them to a long int, then use normal numeric sorting.
              >
              Micha
              >
              Pretty much what Rik said - looks like the way to go - thanks Michael.

              -jools-

              Comment

              • Michael Fesser

                #8
                Re: Is there a PHP command to

                ..oO(jools@by.c om)
                >All google sites are blocked in my firewall.
                Why is that?

                You could get many answers much faster if you would do a quick search on
                Google or the Google Groups archives. Most questions were already asked
                and answered many times before.
                >I did wonder why newsgroups exist.
                Google it. SCNR

                Micha

                Comment

                • Rik Wasmus

                  #9
                  Re: Is there a PHP command to

                  On Tue, 08 Jan 2008 12:01:51 +0100, <jools@by.comwr ote:
                  In article <op.t4kpci035bn juv@metallium.l an>, luiheidsgoeroe@ hotmail.com
                  says...
                  >On Mon, 07 Jan 2008 19:48:09 +0100, <jools@by.comwr ote:
                  >>
                  >
                  Just wondering what the simplest way to sort IP addresses would be
                  Is there a good way to sort that keeps them in sequence
                  asort() sorts on the first character so that doesnt quite do it of
                  >course
                  >>
                  >Convert them to a number (using usort())?
                  >http://nl2.php.net/manual/en/function.ip2long.php
                  >http://nl2.php.net/manual/en/function.long2ip.php
                  >--
                  >Rik Wasmus
                  >>
                  >
                  Aha - I knew there had to be something that helped - thanks Rik.
                  Hmm, come to think of it...
                  Allthough not intended for this use, version_compare () would do the trick
                  without any problems I think. As the behavious of version_compare is
                  clearly defined, and suited for (proven to be valid) IP-addresses, I'd go
                  with that:
                  <?php
                  $array = array(
                  '122.23.45.53',
                  '12.23.46.53',
                  '12.23.45.54',
                  '12.23.45.53',
                  '12.23.'
                  '12.23.45.53');
                  usort($array,'v ersion_compare' );
                  print_r($array) ;
                  ?>

                  ... unless you also need the insurance the IP adress is valid/stuff like
                  256 is captured/converted, in which case ip2long is still better.
                  --
                  Rik Wasmus

                  Comment

                  • jools@by.com

                    #10
                    Re: Is there a PHP command to

                    In article <15m6o3lmevposn r70rdjjtgp51hin qm7d4@4ax.com>, netizen@gmx.de
                    says...
                    >
                    You could get many answers much faster if you would do a quick search on
                    Google or the Google Groups archives. Most questions were already asked
                    and answered many times before.
                    >
                    which part of the words "blocked" and "firewall" don't you understand?

                    And no - I seriously doubt I'd get the answers either faster or better on
                    google even if I could use it as trawling through 30,000 SEO pages of
                    vaguely on topic rubbish more interested in attracting my attention
                    than actually telling me anything useful tends to take time and doesnt
                    have the hands on experience of the users of this group. Nor can it
                    suggest the "best" method of doing things.

                    Even if I could use google a newsgroup is always the best place to look
                    for those and a number of other reasons.

                    -jools-

                    Comment

                    • Paul Lautman

                      #11
                      Re: Is there a PHP command to

                      jools@by.com wrote:
                      In article <15m6o3lmevposn r70rdjjtgp51hin qm7d4@4ax.com>,
                      netizen@gmx.de says...
                      >>
                      >You could get many answers much faster if you would do a quick
                      >search on Google or the Google Groups archives. Most questions were
                      >already asked and answered many times before.
                      >>
                      >
                      which part of the words "blocked" and "firewall" don't you understand?
                      >
                      And no - I seriously doubt I'd get the answers either faster or
                      better on google even if I could use it as trawling through 30,000
                      SEO pages of vaguely on topic rubbish more interested in attracting
                      my attention
                      You will note that when I post a hint about using Google, I usually refer to
                      the "I'm feeling lucky", button. This button takes you straight to the top
                      suggestion in the list. I can accept that if you can't find the answer on
                      the first Google page then maybe it is worth while giving up and asking. But
                      when the answer is on the first hit, all you do by asking here is have
                      others look at that article for you.

                      What a waste of time.


                      Comment

                      • jools@by.com

                        #12
                        Re: Is there a PHP command to

                        In article <op.t4ly5xgf5bn juv@metallium.l an>, luiheidsgoeroe@ hotmail.com
                        says...
                        Hmm, come to think of it...
                        Allthough not intended for this use, version_compare () would do the tric=
                        k =
                        >
                        without any problems I think. As the behavious of version_compare is =
                        >
                        clearly defined, and suited for (proven to be valid) IP-addresses, I'd g=
                        o =
                        >
                        with that:
                        <?php
                        $array =3D array(
                        '122.23.45.53',
                        '12.23.46.53',
                        '12.23.45.54',
                        '12.23.45.53',
                        '12.23.'
                        '12.23.45.53');
                        usort($array,'v ersion_compare' );
                        print_r($array) ;
                        ?>
                        >
                        .. unless you also need the insurance the IP adress is valid/stuff like =
                        =
                        >
                        256 is captured/converted, in which case ip2long is still better.
                        I'll go take a look at that too. Cheers.
                        Validation isn't a problem - I use the Data Minion DSVE for all my
                        validations now - it makes life SO much easier! The forms tool even
                        writes the PHP code for you.
                        I'd give you the link for it but this isn't my own development machine (I
                        can't remember it - or google it from here sadly)

                        -jools-

                        Comment

                        • Michael Fesser

                          #13
                          Re: Is there a PHP command to

                          ..oO(jools@by.c om)
                          >In article <15m6o3lmevposn r70rdjjtgp51hin qm7d4@4ax.com>, netizen@gmx.de
                          >says...
                          >>
                          >You could get many answers much faster if you would do a quick search on
                          >Google or the Google Groups archives. Most questions were already asked
                          >and answered many times before.
                          >>
                          >
                          >which part of the words "blocked" and "firewall" don't you understand?
                          Which part of the word "Why" don't you understand?
                          >And no - I seriously doubt I'd get the answers either faster or better on
                          >google even if I could use it as trawling through 30,000 SEO pages of
                          >vaguely on topic rubbish more interested in attracting my attention
                          >than actually telling me anything useful tends to take time and doesnt
                          >have the hands on experience of the users of this group. Nor can it
                          >suggest the "best" method of doing things.
                          I also mentioned Google Groups, a Usenet archive.

                          On <http://groups.google.c om/group/comp.lang.php/topicsfor example you
                          can get all the knowledge and experience of this group's users from the
                          last couple of years.
                          >Even if I could use google a newsgroup is always the best place to look
                          >for those and a number of other reasons.
                          The best is to do some research on your own first by looking through the
                          archives or some FAQ sites before annoying the newsgroup regulars and
                          wasting their time with asking the same questions over and over again.
                          This is not a help desk.

                          Micha

                          Comment

                          • jools@by.com

                            #14
                            Re: Is there a PHP command to

                            In article <m6u6o3ti5b4mc9 pbfu6u87j1j0vmi v16d9@4ax.com>, netizen@gmx.de
                            says...
                            >
                            The best is to do some research on your own first by looking through the
                            archives or some FAQ sites before annoying the newsgroup regulars and
                            wasting their time with asking the same questions over and over again.
                            This is not a help desk.
                            >
                            Micha
                            >
                            So go through this newsgroup and list the dates this question was asked
                            .... "over and over" - I'll take just the last three -
                            If you cant do that stop wasting everyones time with your self
                            opinionated nonesense that has nothing to do with this newsgroup.

                            This is a newsgroup for questions about PHP. This IS a 'helpdesk'. That
                            is exactly what it is for.

                            if YOU cant answer the questions asked here just keep it shut.

                            -jools-

                            Comment

                            • Michael Fesser

                              #15
                              Re: Is there a PHP command to

                              ..oO(jools@by.c om)
                              >In article <m6u6o3ti5b4mc9 pbfu6u87j1j0vmi v16d9@4ax.com>, netizen@gmx.de
                              >says...
                              >>
                              >The best is to do some research on your own first by looking through the
                              >archives or some FAQ sites before annoying the newsgroup regulars and
                              >wasting their time with asking the same questions over and over again.
                              >This is not a help desk.
                              >
                              >So go through this newsgroup and list the dates this question was asked
                              >... "over and over" - I'll take just the last three -
                              This was not related to your question, but meant in general. Why do you
                              think many popular newsgroups maintain an FAQ? Just for fun?
                              >If you cant do that stop wasting everyones time with your self
                              >opinionated nonesense that has nothing to do with this newsgroup.
                              >
                              >This is a newsgroup for questions about PHP. This IS a 'helpdesk'. That
                              >is exactly what it is for.
                              You get what you pay for. Oh, you didn't pay for this "help desk"?
                              >if YOU cant answer the questions asked here just keep it shut.
                              I already answered your question. For free, BTW! But I have no problem
                              with keeping my mouth shut if you should ever come along with another
                              problem. I couldn't care less.

                              Remember: It's you who wants something from us, not the other way round.

                              And you still didn't answer my question about why you filter Google,
                              'cause I don't see any reason for that. But why should I care at all ...

                              EOT
                              Micha

                              Comment

                              Working...