Please help... I may pull out my hair....
Moderator: General Moderators
- 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....
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.
- dragonsmistress
- Forum Commoner
- Posts: 44
- Joined: Thu Dec 18, 2008 2:03 pm
Re: Please help... I may pull out my hair....
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 (:
- 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....
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 />';
}- dragonsmistress
- Forum Commoner
- Posts: 44
- Joined: Thu Dec 18, 2008 2:03 pm
Re: Please help... I may pull out my hair....
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?
there can't be a name in the script already since users will enter their own names. See what I'm saying?
- dragonsmistress
- Forum Commoner
- Posts: 44
- Joined: Thu Dec 18, 2008 2:03 pm
Re: Please help... I may pull out my hair....
also... how can i bring up the actual image instead of the text? sorry
Like my title says... newbie ):
- 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....
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:
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>'
}- dragonsmistress
- Forum Commoner
- Posts: 44
- Joined: Thu Dec 18, 2008 2:03 pm
Re: Please help... I may pull out my hair....
hmmmm...getting this
Parse error: syntax error, unexpected '/' in /home/hdragons/public_html/test3.php on line 35
- dragonsmistress
- Forum Commoner
- Posts: 44
- Joined: Thu Dec 18, 2008 2:03 pm
Re: Please help... I may pull out my hair....
*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 (:
I know this seems silly but it's my hobby. I'm a stay at home mommy so gotta do SOMETHING (:
- 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....
Change the third echo statement in the loop from:
to:
Code: Select all
echo 'Image: $list[$i] . $ext . '</p>'Code: Select all
echo 'Image: ' . $list[$i] . $ext . '</p>'- 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....
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.
- dragonsmistress
- Forum Commoner
- Posts: 44
- Joined: Thu Dec 18, 2008 2:03 pm
Re: Please help... I may pull out my hair....
hmmm.. what do I need to look for to stop the adults from pulling up?
- dragonsmistress
- Forum Commoner
- Posts: 44
- Joined: Thu Dec 18, 2008 2:03 pm
- dragonsmistress
- Forum Commoner
- Posts: 44
- Joined: Thu Dec 18, 2008 2:03 pm
Re: Please help... I may pull out my hair....
this first code that you did works better (I added some for the form and to make the images display
How can we add in to make it work to only pull up eggs and hatchlings? That's all this code needs (:
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 />";
}
?>- dragonsmistress
- Forum Commoner
- Posts: 44
- Joined: Thu Dec 18, 2008 2:03 pm
Re: Please help... I may pull out my hair....
*sigh* back to pulling my hair out ):
- 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....
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.
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.