I'm going to stab the next array that does not obey me in the eye.

Okay here's what I got.

I have a multidimensional $array. (stop me at any point if I'm wrong). Keys are things like [0] => [guid] [link] [title][desc], [1] => [guid] [link] [title][desc] etc. Values have HTML.

I array_popped the last item [24] off and exploded out the [desc] key into $new_array. When printed, the array resolves itself into a lovely associative array.

Here's the issue.

I want to crawl the $new_array's values for a string. Let's say, a username. If the username is in that key's value, I want to grab the whole value and explode it some more for db storage. So far all attemps at searching have failed. There is only one key in the array that has the value I want, but it's never in the same place depending on when I am pulling the feed.

please help!

    Are you saying that the userid might possibly exist in the value for the title? the description? link? And you want to find it no matter where it exists in $new_array ?

    Is $new_array always comprised of the same four elements? ( [guid] [link] [title][desc] ) Or is it possible that some instance of $new_array might have additional or different elements?

      Couple of things...

      1. Oops. Okay, $new_array is the last of $array and DOES have those keys [guid]/[title]/[desc]. It's the last "game" of the feed I pull. I'm only interested in [desc] of the game to extract the rank, deaths, kills, assists... it looks like this (bear with me this is by memory, no access to the code from work):
       array
      [0]
        [guid] http://....someurl
        [title] USERNAME's games
        [desc] Blah<br>text text <br> Text <br><br> USERNAME: 5th, 6, 8, 0
      
      [1]
        [guid] http://....someurl.2
        [title] USERNAME's games
        [desc] Blah<br>text text <br> Text <br><br> USERNAME: 1st, 3, 5, 9
      
      [2]
        [guid] http://....someurl.3
        [title] USERNAME's games
        [desc] Blah<br>text text <br> Text <br><br> USERNAME: 4th, 4, 3, 10
      
      ^ I pop off the last one
      
      

      then get

       new_array:
      [2] 
        [guid] http://....someurl
        [title] USERNAME's games
        [desc] Blah<br>text text <br> Text <br><br> USERNAME: 4th, 4, 3, 10
      

      so I make a $new_new_array by "asploding" out [desc] and I get:

      new_new_array
      [0] Blah
      [1] text text
      [2] Text
      [3] USERNAME: 4th, 4, 3, 10 <---------------this is the baby I want..
      
      
      

      If there's a quick and dirty way to yank that out, the better!!!

      1. I can't remember what else I was gonna say

        So once you have $new_new_array, can't you just say:

        $username = $new_new_array[3];
        or
        echo $new_new_array[3];

        Or are you saying you want to extract the part that comes after the word "USERNAME:" in the value? For that you'd need a simple regular expression. Sorry, I'm still not certain what you're looking for.

          Yes, I want to parse what's after [3] USERNAME: ...I want to store those values in a database for statistics on the gamers. However, it won't always be [3], it will always change what key the username will be in with the values I need. So I need to search, match, preg something, I don't know. I know what to do AFTER I have the new_new_new_array with those 4 numbers, but the search part is kicking my butt!!!

            To iterate through all the elements in $new_new_array, I use the foreach command like this:

            foreach { $new_new_array as $x) {
            print "$x------";
            }

            This is a loop that will happen 4 times if your array has elements [0], [1], [2], and [3]. Then inside the loop, you will have $x which represents the part you're working with at the moment. In other words, the first time through the loop, $x will be $new_new_array[0] and the 2nd time through the loop, $x will be $new_new_array[1] etc until the array is exhausted.

            Then, inside the loop, you check to see if $x starts with the word "USERNAME:" like this:

            foreach ( $new_new_array as $x) {
            if (ereg("USERNAME:(.+)",$x,$regs)) { $username = $regs[1]; }
            }

            The .+ means "any characters that follow "USERNAME:" and the parentheses around .+ mean that the ereg command should store those characters in an array called $regs. Once the loop is finished, $username will have a value of whatever followed USERNAME: in any one of the elements of the array.

              Write a Reply...