Page 3 of 4

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

Posted: Fri Dec 19, 2008 5:48 pm
by RobertGonzalez
I feel you. I still have my editor open. I am in the middle of something at work though so it might have to wait a bit longer.

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

Posted: Fri Dec 19, 2008 5:54 pm
by dragonsmistress
Hey... I can wait!! I'm no longer pulling my hair out (: You've helped so much! I put a thank you to you in my site (:

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

Posted: Fri Dec 19, 2008 6:32 pm
by RobertGonzalez
This feels dirty to me for some reason, but my regex skillz are not as mad as some of my other skillz. ;)

Code: Select all

<?php
// Set the host of where things are going to get stuff from
$host = 'http://dragcave.net';
 
// Set the user - THIS WILL HOOK INTO YOUR FORM
$user = 'dragonmistress'; // Will be set by the form
 
// Set the fetch URL
$url = $host . '/user/' . $user;
 
// Get the contents of the HTML output for the user
$string = file_get_contents($url);
 
// Path builders for the regular expression and the HTML that follows
$path = '/image/';
$ext = '.gif';
 
// Regular expression pattern
$pattern = "#$path(.*?)$ext(.*?)</td><td>(Egg|Hatchling)</td><td>#mi";
 
// Do it. Do it. - A la Starsky and Hutch
preg_match_all($pattern, $string, $matches);
 
// Prepare to loop
$list = $matches[1]; // These are the image names
$type = $matches[3]; // These are the image types
$limit = count($list); // This is how many there are
 
// Loop it now and output to see how it looks
// You might want to changes this to something else in your code
for ($i = 0; $i < $limit; $i++) {
    echo $host . $path . $list[$i] . $ext . ' is a ' . $type[$i] . '<br />';
}

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

Posted: Fri Dec 19, 2008 6:48 pm
by dragonsmistress
this confuses me.....

there can't be a name in the script already since users will enter their own names. See what I'm saying?

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

Posted: Fri Dec 19, 2008 6:54 pm
by dragonsmistress
also... how can i bring up the actual image instead of the text? sorry :oops: Like my title says... newbie ):

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

Posted: Fri Dec 19, 2008 7:16 pm
by RobertGonzalez
In the comments I mention that the user name will come from the form. Or whatever mechanism you are using to fetch the username. It shouldn't be hard coded but rather come from a source. What that source is, you get to decide. :)

As for showing the image, you just want to output the html for the image, which would be something like:

Code: Select all

<?php
for ($i = 0; $i < $limit; $i++) {
    echo '<p><img src="' . $host . $path . $list[$i] . $ext . '<br />';
    echo 'Type: ' .  $type[$i] . ' <br />';
    echo 'Image: $list[$i] . $ext . '</p>'
}

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

Posted: Fri Dec 19, 2008 7:20 pm
by dragonsmistress
hmmmm...getting this
Parse error: syntax error, unexpected '/' in /home/hdragons/public_html/test3.php on line 35

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

Posted: Fri Dec 19, 2008 7:22 pm
by dragonsmistress
*cries* it's also pulling up adults as hatchlings LOL
I know this seems silly but it's my hobby. I'm a stay at home mommy so gotta do SOMETHING (:

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

Posted: Fri Dec 19, 2008 7:23 pm
by RobertGonzalez
Change the third echo statement in the loop from:

Code: Select all

echo 'Image: $list[$i] . $ext . '</p>'
to:

Code: Select all

echo 'Image: ' . $list[$i] . $ext . '</p>'

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

Posted: Fri Dec 19, 2008 7:26 pm
by RobertGonzalez
What the pattern is doing is looking for an image, then looking forward just a bit to see if it comes across either 'egg' or 'hatchling' and only pulling images that are of those two types.

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

Posted: Fri Dec 19, 2008 7:26 pm
by dragonsmistress
hmmm.. what do I need to look for to stop the adults from pulling up?

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

Posted: Fri Dec 19, 2008 8:20 pm
by dragonsmistress
Anyone? :(

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

Posted: Fri Dec 19, 2008 8:30 pm
by dragonsmistress
this first code that you did works better (I added some for the form and to make the images display

Code: Select all

<?php
$scrollname = $_POST['scrollname'];
if (isset($_POST['submit'])) {
}
 $string = file_get_contents('http://dragcave.net/user/' . $scrollname);
$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 />";
}
?>
How can we add in to make it work to only pull up eggs and hatchlings? That's all this code needs (:

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

Posted: Fri Dec 19, 2008 10:30 pm
by dragonsmistress
*sigh* back to pulling my hair out ):

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

Posted: Sat Dec 20, 2008 12:15 am
by RobertGonzalez
Try not to bump your own threads. It is against the rules and can get you warned around here. ;)

What denotes an egg and a hatchling vs an adult hatchling? The pattern I showed in the code I posted look specifically for the word "egg" and "hatchling" in the row it is on.