1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help with getting exact contents

Discussion in 'PHP' started by dragonsmistress, Dec 20, 2008.

  1. #1
    I'm having trouble with a script for my site.
    I'm trying to pull a user's dragons from their scroll on the dragcave.net website.
    But I want to specifically display either just the eggs or just the hatchlings. Let me know if I need to provide more info. Here is my script:

    <?php
       $scrollname = $_POST['scrollname'];
       if (isset($_POST['submit'])) {
     }
       $string = file_get_contents('http://dragcave.net/user/' . $scrollname);
       // Path builders for the regular expression and the HTML that follows
       $path = '/image/';
       $ext = '.gif';
    
       $pattern = "#$path(.*?)$ext(.*?)#";
       preg_match_all($pattern, $string, $matches);
       $list = $matches[1];
       $limit = count($list);
       for ($i = 0; $i < $limit; $i++) {
             echo "<img src=\"http://dragcave.net/image/$list[$i].gif\"><br />";
             echo 'Code: ' . $list[$i] . '<br>';
     }
    ?>
    Code (markup):
    here is my scroll if you need to check the source code of the page
    -http://dragcave.net/user/dragonsmistress

    Please Please help me ): I've been trying to figure this out for months now!! :confused:
     
    dragonsmistress, Dec 20, 2008 IP
  2. misbah

    misbah Active Member

    Messages:
    265
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    68
    #2
    did you mean like this
    <?php
    $scrollname = $_POST['scrollname'];
    if (isset($_POST['submit'])) {
    	$string = file_get_contents('http://dragcave.net/user/' . $scrollname);
    	// Path builders for the regular expression and the HTML that follows
    	$path = '/image/';
    	$ext = '.gif';
    
    	$pattern = "#$path(.*?)$ext(.*?)#";
    	preg_match_all($pattern, $string, $matches);
    	$list = $matches[1];
    	$limit = count($list);
    	for ($i = 0; $i < $limit; $i++) {
    		echo "<img src=\"http://dragcave.net/image/$list[$i].gif\"><br />";
    		echo 'Code: ' . $list[$i] . '<br>';
    	}
    }
    ?>
    PHP:
     
    misbah, Dec 20, 2008 IP
  3. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Simple fix for ya. All you have to do is add another thing to your $pattern string. Try this

    $pattern = "#$path(.*?)$ext(.*?)(Egg|Hatchling|Adult)#";


    Then, the string "Egg" or "Hatchling" or "Adult" will be inside the 3rd key of your $matches array ($matches[3]) so you could do like

    <?php
       $scrollname = $_POST['scrollname'];
       if (isset($_POST['submit'])) {
     }
       $string = file_get_contents('http://dragcave.net/user/' . $scrollname);
       // Path builders for the regular expression and the HTML that follows
       $path = '/image/';
       $ext = '.gif';
    
       $pattern = "#$path(.*?)$ext(.*?)(Egg|Hatchling|Adult)#";
       preg_match_all($pattern, $string, $matches);
       $list = $matches[1];
       $type = $matches[3];
       $limit = count($list);
       for ($i = 0; $i < $limit; $i++) {
             echo "<img src=\"http://dragcave.net/image/$list[$i].gif\"><br />";
             echo 'Code: ' . $list[$i] . '<br>';
             echo 'Type: ' . $type[$i] . '<br>'; //This is the new line I added showing how to handle the type
     }
    ?>
    PHP:

    EDIT: @misbah: Nah, their script already appears to run fine (though I didn't do it through a post submission so I don't know if that's messing them up at all) but what they wanted was to be able to see the Type of the thing (Egg or Hatchling) then later on only show them based on that Type.
     
    zerxer, Dec 20, 2008 IP
  4. dragonsmistress

    dragonsmistress Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    LOL.....nm let me go try that!!
     
    dragonsmistress, Dec 20, 2008 IP
  5. dragonsmistress

    dragonsmistress Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It still seems to be pulling up all the dragons... ):I removed the Adult part and it is still pulling all the dragons up.
     
    dragonsmistress, Dec 20, 2008 IP
  6. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #6
    No no no. I didn't put in any checks for only showing whatever. I figured you'd know to do that much lol. What you'd have to do is put an IF in your for loop like

    if($type[$i] == "Hatchling") {
    //print it out here
    }

    which will only print out the code for Hatchlings. Example.

    <?php
       $scrollname = $_POST['scrollname'];
       if (isset($_POST['submit'])) {
     }
       $string = file_get_contents('http://dragcave.net/user/' . $scrollname);
       // Path builders for the regular expression and the HTML that follows
       $path = '/image/';
       $ext = '.gif';
    
       $pattern = "#$path(.*?)$ext(.*?)(Egg|Hatchling|Adult)#";
       preg_match_all($pattern, $string, $matches);
       $list = $matches[1];
       $type = $matches[3];
       $limit = count($list);
       for ($i = 0; $i < $limit; $i++) {
             if($type[$i] == "Hatchling") {
                 echo "<img src=\"http://dragcave.net/image/$list[$i].gif\"><br />";
                 echo 'Code: ' . $list[$i] . '<br>';
            }
     }
    ?>
    PHP:
     
    zerxer, Dec 20, 2008 IP
  7. dragonsmistress

    dragonsmistress Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    WOW!!!! You do not understand how appreciative I am for this :) *BIG GRIN* That works like a charm!! I didn't know how to do the if statement!! LOL I'm a newbie at php so I wasn't sure!!! Gosh... thank you SO much! I must give you credit on my site!! Thank you Thank You Thank YOU!!!!!:D
     
    dragonsmistress, Dec 20, 2008 IP
  8. dragonsmistress

    dragonsmistress Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    One more thing.... not sure if you can help me with this part and if not I don't even care (I'm so happy) But... the users can "freeze" their hatchlings making them no longer need to be posted on the site. Would you know how to keep from showing the frozen hatchlings? Like I said... if not no biggie at all!! *still grinning*
     
    dragonsmistress, Dec 20, 2008 IP
  9. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #9
    You'd have to freeze one of your eggs for me so I can see how it's displayed on your profile page. I'd need an example.
     
    zerxer, Dec 20, 2008 IP
  10. dragonsmistress

    dragonsmistress Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I have several frozen hatchlings (you can't freeze eggs) here is the url for a frozen hatchling:

    http://dragcave.net/viewdragon/n/Mistress%27s%20Mortuus
     
    dragonsmistress, Dec 20, 2008 IP
  11. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Nope, sorry. There doesn't seem to be any indication in the profile view's HTML that says whether or not it's frozen. The most you can do is have it open the viewdragon page for every hatchling and look for the text that describes it as frozen but you really don't want to do that because that's a lot of external file opening and can really slow your script down.
     
    zerxer, Dec 20, 2008 IP
    dragonsmistress likes this.
  12. dragonsmistress

    dragonsmistress Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Well thank you so much again :)
     
    dragonsmistress, Dec 20, 2008 IP
  13. dragonsmistress

    dragonsmistress Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I was wondering if you, zerxer, or anyone can help with my next phase :) Is it possible to allow users to update their data in the database without having to re add ALL the codes. Like say:

    A user has x amount of dragons and submits those into the db
    Then.... the next day gets another egg/hatchling and wants to add that to the site.

    Is it possible for them to add this egg/hatchling without re adding the dragons from the day before?

    Thanks :)
    This is the best forum I've found yet!!
     
    dragonsmistress, Dec 21, 2008 IP
  14. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #14
    It's possible.. I'll PM you again.
     
    zerxer, Dec 21, 2008 IP