Sort a array of substring

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ladamo78
    New Member
    • Apr 2012
    • 8

    Sort a array of substring

    Hi,
    I need to order an array contains the strings order by
    name server (iclsvi2 or iclsvi2 o iclsvi3)

    service:ACS iclsvi2 started
    service:ALM iclsvi2 started
    service:BSOL iclsvi1 started
    service:DBAPEX iclsvi1 started
    service:DOCST iclsvi2 started

    here the result I need

    service:BSOL iclsvi1 started
    service:DBAPEX iclsvi1 started
    service:ACS iclsvi2 started
    service:ALM iclsvi2 started
    service:DOCST iclsvi2 started

    Anyone can help me please?
    Thx so mutch
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Grab the first 7 characters after the first space. Then you can use that to sort.

    The strpos() function will find the position of the first occurrence of a substring. Use that to find the space. The substr function will return a substring from a string. Use that to pull the 7 characters after the space. After that you can sort with whatever sort algorithm you want to use.

    Comment

    • ladamo78
      New Member
      • Apr 2012
      • 8

      #3
      Thx Rabbit for the answear but I have these follow problem.

      1) the log report I must order have different blank space between service:ACS and iclsvi2
      2) I have a lot of name server iclsvi2, iclsvi1 but also webse02 or otrweb3 and so on

      I would know how extrac name server of these different string to order.
      In the Unix sheel there is a command to select a portion of string at coloumn 2 rather than column 1 or coloumn 3.
      I don't know if is possible with PHP language.

      Anyone can help me please?
      Thx so mutch

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        You really have to mention that kind of stuff at the very beginning. How do you expect to get the right answer if you give us non-representative data?

        Please post a new sample dataset containing the different variations contained in your data. Only then can we work towards a correct solution.

        Comment

        • ladamo78
          New Member
          • Apr 2012
          • 8

          #5
          There are a lot of log files from server.
          They rappresent the status of cluster.
          The log files are send in a directory and I must open order and pubblic on web.
          The log files are all similar (ALIAS DB follow by CLUSTER NAME follow by STATUS) like the example I post.
          I can't extract the string CLUSTER NAME because how I try to explain it's change for every log files and I can't permit to analyze all kind of logs files because are thousend!
          I know only the structure of the log files.
          Each rows have
          ALIAS NAME [number of irregular blank space] CLUSTER NAME [number of irregular blank space] STATUS

          Hope now my problem is more clear

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            So the number of spaces around the cluster name is unknown. But it looks like there's no spaces before or after the entire row. Use a regular expression to find the portion of the string that is bound by a space on each end. That will be your cluster name.

            Comment

            • ladamo78
              New Member
              • Apr 2012
              • 8

              #7
              Do you know what expression can I use to find portion of the string that is bound by a space on each end ? thx

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                This expression would do it.
                Code:
                \s(\w+)\s

                Comment

                • ladamo78
                  New Member
                  • Apr 2012
                  • 8

                  #9
                  Sorry is a PHP expression???
                  what mean \s(\w+)\s?

                  Comment

                  • Rabbit
                    Recognized Expert MVP
                    • Jan 2007
                    • 12517

                    #10
                    It's the regular expression I mentioned in the previous post.

                    Comment

                    • ladamo78
                      New Member
                      • Apr 2012
                      • 8

                      #11
                      is not clear.
                      Hope to find one solution on this form.
                      wrong idea

                      Comment

                      • Rabbit
                        Recognized Expert MVP
                        • Jan 2007
                        • 12517

                        #12
                        It's not clear because you don't know what regular expressions are. You should look up the documentation in php on it.

                        Comment

                        • ladamo78
                          New Member
                          • Apr 2012
                          • 8

                          #13
                          Thanks Rabbit for your suggest.
                          Strange I don't thought about...
                          I'm not a PHP developer and I have few time to resolve these problem so I sign here to these form for a quick response from PHP developer.
                          If your solution is study the documentation on PHP... thank you...you solution is \s(\w+)\s ???? you think is clear for a not PHP developer?
                          In other response about these argument anyones post ad example or try to be clear most possibleand you say me to study the documentation?
                          for me was more help if you give me ad example of function to order an array or to help me to find another solution....

                          Comment

                          • Rabbit
                            Recognized Expert MVP
                            • Jan 2007
                            • 12517

                            #14
                            I don't give out code unless the requestor has shown a willingness to learn what's required. If you're working in PHP, but don't know PHP, I expect you to learn it. I'm not here to spoon feed you answers.

                            Comment

                            • ladamo78
                              New Member
                              • Apr 2012
                              • 8

                              #15
                              anddddd is with an example you can explain, teacher ! example not solution teacher, you know the different?

                              Comment

                              Working...