dylandcor Posted April 24, 2007 Share Posted April 24, 2007 Is there any way I could get the information from this page (http://www.mapletip.com/rankcapture.php?name=dylandcor2&check=true) such as level and experience into a variable so I can use it to create an image. The page that is linked isn't mine, so I don't know how it is set up. I know how to create the image, I just can't seem to get all of the data out of the page. Any help would be appreciated! Link to comment https://forums.phpfreaks.com/topic/48503-solved-getting-data-from-another-page/ Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 to get the values you would do <?php echo $_GET['name']; echo "<br>"; echo $_GET['check']; ?> this will print dylandcor2 true of couse you can use them anyway you see fit if thats what you asking if not then try fread Link to comment https://forums.phpfreaks.com/topic/48503-solved-getting-data-from-another-page/#findComment-237242 Share on other sites More sharing options...
dylandcor Posted April 24, 2007 Author Share Posted April 24, 2007 Thank you for the quick reply, but your $_GET idea didn't work, seeing as I don't know what the site called the variables. I also just tried this code <?php $filename = "http://www.mapletip.com/rankcapture.php?name=dylandcor2&check=true"; $file = fopen($filename, "r"); $size = filesize( $file ); $text = fread($filename, $filesize); fclose($filename); echo $text; ?> And it gave me this error: Warning: filesize() [function.filesize]: stat failed for Resource id #3 in C:\Documents and Settings\Dylan\Desktop\html\get.php on line 5 Warning: fread(): supplied argument is not a valid stream resource in C:\Documents and Settings\Dylan\Desktop\html\get.php on line 6 Warning: fclose(): supplied argument is not a valid stream resource in C:\Documents and Settings\Dylan\Desktop\html\get.php on line 7 Link to comment https://forums.phpfreaks.com/topic/48503-solved-getting-data-from-another-page/#findComment-237251 Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 humm maybe file_get_contents($url); Link to comment https://forums.phpfreaks.com/topic/48503-solved-getting-data-from-another-page/#findComment-237254 Share on other sites More sharing options...
dylandcor Posted April 24, 2007 Author Share Posted April 24, 2007 Ok, that worked. It shows the page in its fullness now. Do you know how to search for a string like "Level: 49" and have that value be a variable in my script? If someone knows, that would be great! Link to comment https://forums.phpfreaks.com/topic/48503-solved-getting-data-from-another-page/#findComment-237256 Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 well this may work of course $subject = the data <?php $subject = "blarassgdyasdg sdgyasud Level: 49 gdsdjg ashd gashd gsahd gsahj"; if (preg_match('/Level: (\\d+)/', $subject, $regs)) { $result = $regs[1]; } echo "$result<br />"; ?> Link to comment https://forums.phpfreaks.com/topic/48503-solved-getting-data-from-another-page/#findComment-237261 Share on other sites More sharing options...
dylandcor Posted April 24, 2007 Author Share Posted April 24, 2007 Ok, That works great, just one more question, and then I think this topic is solved. Using your code, if I want all of the data, how do I go about changing the variables in your code so I could find the name of the character, the experience and such? Also, what exactly is the $regs variable? My code so far: <?php $filename = "http://www.mapletip.com/rankcapture.php?name=dylandcor2&check=true"; $file = file_get_contents($filename); if (preg_match('/Level: (\\d+)/', $file, $regs)) { $result = $regs[1]; } echo "The Level is $result<br />"; ?> Link to comment https://forums.phpfreaks.com/topic/48503-solved-getting-data-from-another-page/#findComment-237268 Share on other sites More sharing options...
dylandcor Posted April 24, 2007 Author Share Posted April 24, 2007 Can anyone please explain to me what \\d+ and $regs mean in the code so I know what to change when I go to add the other stats? Link to comment https://forums.phpfreaks.com/topic/48503-solved-getting-data-from-another-page/#findComment-237305 Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 sorry about that needed a break OK, this works pretty well <?php $filename = "http://www.mapletip.com/rankcapture.php?name=dylandcor2&check=true"; $file = file_get_contents($filename); if (preg_match('/Rank: (\\w+).*Name: (\\w+).*World: (\\w+).*Job: (\\w+).*Level: (\\w+).*Experience: ([0-9,]*).*Movement: (\\w+ (?:\\w+)?)/sm', $file, $regs)) { $Rank = $regs[1]; $Name = $regs[2]; $World = $regs[3]; $Job = $regs[4]; $Level = $regs[5]; $Experience = $regs[6]; $Movement = $regs[7]; echo "The Rank is $Rank<br />"; echo "The Name is $Name<br />"; echo "The World is $World<br />"; echo "The Job is $Job<br />"; echo "The Level is $Level<br />"; echo "The Experience is $Experience<br />"; echo "The Movement is $Movement<br />"; } ?> as for the regs they are results from RegularExpressions aka RegEx, something i have been praticing with.. Link to comment https://forums.phpfreaks.com/topic/48503-solved-getting-data-from-another-page/#findComment-237318 Share on other sites More sharing options...
dylandcor Posted April 24, 2007 Author Share Posted April 24, 2007 Thank you so much, Problem Solved!!!! Link to comment https://forums.phpfreaks.com/topic/48503-solved-getting-data-from-another-page/#findComment-237321 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.