...

View Full Version : php parsing



UrbanTwitch
08-26-2009, 12:41 AM
I'm trying doing a simple parser but it's not working, :\


<?php
if (!$_GET['q']) {
die("Please specify a world using ?q=<u>d3966c12bd8409f4373ce595b8f9d07e</u>");
}
$file = file_get_contents("http://minecraft.net/servers.jsp");
preg_match("/<a href=\"play.jsp?server=$_GET[q]\"><b>(.*?)<\/b><\/a>/",$file,$ok);
echo "If server is up... the name will display ".$ok[1]."\n";
?>

I am getting the content of http://minecraft.net/servers.jsp and see if a specific Url (i.e d3966c12bd8409f4373ce595b8f9d07e) is on that list. If it is, then it will display the name.. if not.. then it won't.

However, It's not working. I've tried several online ones and all i get is blanks.

_Aerospace_Eng_
08-26-2009, 01:23 AM
Change this

preg_match("/<a href=\"play.jsp?server=$_GET[q]\"><b>(.*?)<\/b><\/a>/"
to this

preg_match("/<a href=\"play.jsp?server=".htmlentities($_GET['q'])."\"><b>(.*?)<\/b><\/a>/"
I don't know if your expression is right but I do know your $_GET isn't in there properly.

UrbanTwitch
08-26-2009, 01:50 AM
Nope, that didn't work.
New code:

<?php
$id = htmlentities($_GET['q']);
if (!$_GET['q']) {
die("Please specify a world using ?q=<u>d3966c12bd8409f4373ce595b8f9d07e</u>");
}
$file = file_get_contents("http://minecraft.net/servers.jsp");

if (preg_match("/$id/i", $file)) {
echo "<h1>worked!</h1>";
}else{
echo "<h2>nope</h2>";
}
?>

tomws
08-26-2009, 04:06 AM
The code in your last post works here.

_Aerospace_Eng_
08-26-2009, 04:49 AM
Same here. What are you using as q?

UrbanTwitch
08-26-2009, 05:02 AM
The part after server=. The bunch of letters/numbers.

For example: ?q=f7b9d3823fb2519b6ed7a83375aa4e0b

This is wrong. It says nope to me but yet when I go to http://minecraft.net/servers.jsp.. I see World Of Minecraft (the server in the for example) that it's up.

So it's wrong. :\

tomws
08-26-2009, 05:05 AM
I tried it with real, online servers like "Redshift's Ocean Build" and just a part of a name like "tactical". Also tried with a fake name. I don't know where your test string is coming from.

UrbanTwitch
08-26-2009, 05:09 AM
Oh, it works with names but not with the long server url? That's dumb. :(

tomws
08-26-2009, 05:50 AM
I don't see any long server URLs. I don't have an account, so maybe things look different when logged in.

_Aerospace_Eng_
08-26-2009, 06:01 AM
Actually that might be what is happening. file_get_contents will see the page as if you weren't logged in. If you aren't logged in that query string is nowhere to be found in the source code.

UrbanTwitch
08-26-2009, 06:54 AM
OHH!~! That's why. Thanks so much! :-P I knew It had to be something.

Dang, thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum