Please help... I may pull out my hair....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Please help... I may pull out my hair....

Post by RobertGonzalez »

f-g-c meaning file_get_contents? Can you post the URI that you are getting the contents from? If it is something private you can PM me. I would like to see the contents that you are fetching so I can see where to move to next.
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Re: Please help... I may pull out my hair....

Post by dragonsmistress »

No problem at all! I appreciate your help by the way (: http://dragcave.net/user/dragonsmistress

The name would be whatever the user enters into the form but for purpose sakes we can use my username
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Please help... I may pull out my hair....

Post by RobertGonzalez »

I get it. So you are actually taking the HTML of that file and scanning it for images (only GIF images it looks like). Once you have those images you are going to list them and compare them to something right? Or is that wrong?

So basically you are going to take the images from that site and list them on your site for your users to check off?
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Re: Please help... I may pull out my hair....

Post by dragonsmistress »

You've got it!!! lol not comparing them to anything just letting the users see what eggs and hatchlings they have and then they can click the ones they would like to have displayed on my site
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Please help... I may pull out my hair....

Post by RobertGonzalez »

Ok. Hang tight and let me see if I can whip something up really quick.
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Re: Please help... I may pull out my hair....

Post by dragonsmistress »

you are my new best friend (;
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Please help... I may pull out my hair....

Post by RobertGonzalez »

So with the help of another forum moderator here (*cough* Pickle *cough*) I was able to get a listing of images for your from the site:

Code: Select all

<?php
$string = file_get_contents('http://dragcave.net/user/dragonsmistress');
$pattern = ":/image/(.*?).gif:m";
preg_match_all($pattern, $string, $matches);
$list = $matches[0];
$limit = count($list);
for ($i = 0; $i < $limit; $i++) {
    echo "http://dragcave.net$list[$i]<br />";
}
Replace the url with the url of the user you are doing this for. Also, you may want, for testing anyway, to var_dump the $matches array after you have it to see what it is really composed of. The 0th member of the matches array is the "/image/XXXX.gif" string. The 1th array are the image names only. I added the dragoncave URI to the output so you could feasibly render those images on your site as they are coming out.

I gotta head out. Hopefully this puts you on the right track. If not, you can always post back. Good luck with your project.
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Re: Please help... I may pull out my hair....

Post by dragonsmistress »

this works great (: only thing i need now is a form so the user can enter the scrollname and have the eggs and hatchlings pulled up... any thoughts?
i also need to know how to ONLY list the eggs and hatchlings... not the adults (:
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Please help... I may pull out my hair....

Post by Chris Corbyn »

In ~Everah's code he gets the contents from a URL that has your username hard-coded into it:

Code: Select all

$string = file_get_contents('http://dragcave.net/user/dragonsmistress');
If you had a form with a field called "scrollname" that points to this page, then you'd access the scrollname variable via $_POST['scrollname'] or $_GET['scrollname'] depending upon what method=" ... " you have in your form.

So you need to replace that hard-coded username with the data from the form:

Code: Select all

//Assuming you've done some pre-requisite isset() for $_POST['scrollname']
$scrollname = $_POST['scrollname'];
$string = file_get_contents('http://dragcave.net/user/' . $scrollname);
That should give you a head-start on making things more dynamic so a user can specify their scrollname.

Ok, where's my lovin' ? :lol:
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Re: Please help... I may pull out my hair....

Post by dragonsmistress »

Just got home from a Canes game!!! Goooo Canes (: Anyways.....

Here is my form

Code: Select all

<form action="test.php" method="post">
    <div style='margin: 0px auto; text-align: center;'> Scrollname: <input name="scrollname"/> <input type="submit" value="Add"/></div>
</form>
And here is the script

Code: Select all

<?php
 $scroll = $_POST[scrollname];
if (isset($_POST['submit'])) {
 $string = file_get_contents('http://dragcave.net/user/' . $scroll);
 $pattern = ":/image/(.*?).gif:m";
 preg_match_all($pattern, $string, $matches);
 $list = $matches[0];
 $limit = count($list);
 for ($i = 0; $i < $limit; $i++) {
     echo "<img src=http://dragcave.net$list[$i]><br />";
 }
}
?>
I get a blank page ):
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Re: Please help... I may pull out my hair....

Post by dragonsmistress »

Ok..... I got that to work (: NOW (: Loving will come if you can help me figure out how to ONLY list the eggs and hatchlings!!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Please help... I may pull out my hair....

Post by RobertGonzalez »

On the page you are scraping, what identifies the image as an egg as opposed to a hatchling as opposed to a dragon?
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Re: Please help... I may pull out my hair....

Post by dragonsmistress »

The source code on the site for the eggs is:
<tr><td><img src="/image/g3Jn.gif" alt='x'/></td><td>&nbsp;</td><td>Egg</td>
Source code for hatchling:
<tr><td><img src="/image/MYZX.gif" alt='x'/></td><td><i>Unnamed</i></td><td>Hatchling</td>
Source code for adult:
<tr><td><img src="/image/v4Jo.gif" alt='x'/></td><td>Mistress's Rutilus</td><td>Adult</td>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Please help... I may pull out my hair....

Post by RobertGonzalez »

Ok, that will take a bit of mesaging the regular expression, but it should be easy enough. Let me see if I can figure out the regular expression (not one of my strong suits).
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Re: Please help... I may pull out my hair....

Post by dragonsmistress »

*waits ever so patiently* :mrgreen:
Post Reply