Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11

Thread: php parsing

  1. #1
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post

    php parsing

    I'm trying doing a simple parser but it's not working, :\

    PHP Code:
    <?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.
    Formerly MysticScript

    6+ years club

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Change this
    PHP Code:
    preg_match("/<a href=\"play.jsp?server=$_GET[q]\"><b>(.*?)<\/b><\/a>/" 
    to this
    PHP Code:
    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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post
    Nope, that didn't work.
    New code:
    PHP 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>";
      }
    ?>
    Formerly MysticScript

    6+ years club

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    The code in your last post works here.
    Are you a Help Vampire?

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Same here. What are you using as q?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post
    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. :\
    Last edited by UrbanTwitch; 08-26-2009 at 04:08 AM.
    Formerly MysticScript

    6+ years club

  • #7
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    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.
    Are you a Help Vampire?

  • #8
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post
    Oh, it works with names but not with the long server url? That's dumb.
    Formerly MysticScript

    6+ years club

  • #9
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    I don't see any long server URLs. I don't have an account, so maybe things look different when logged in.
    Are you a Help Vampire?

  • #10
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #11
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post
    OHH!~! That's why. Thanks so much! :-P I knew It had to be something.

    Dang, thanks.
    Formerly MysticScript

    6+ years club


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •