Closed Thread
Results 1 to 10 of 10

Thread: regex (yuck)

  1. #1
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    regex (yuck)

    ok so i have this script that displays the content of a webpage
    Code:
    <?php
    $url 
    "https://www.novaworld.com/Players/Stats.aspx?id=33680801261&p=616065";

    //Gets the content of the submited URL;
    $content file_get_contents($url); 

    //Strips the tags of the $content;
    $strip strip_tags($content);

    //Removes Everything in the up to For:;
    $remove stristr($strip'Hawk Down');

    //Declares $remove as $getstats;
    $stats $remove;
    echo 
    $stats;
    ?>
    what i want to do is parse the name Ozymandias from the $stats string. While trying to build my regex i used a pseudo-code so i could avoide the long load of getting the actual content of the website. The psuedo code is below:
    Code:
    <?php
    $string 
    'Down Ozymandias. Rank: 1-Star General ( 14 ) PCID: A13-3E71AC Player Created: June 9, 2006 TABLE.statsx ';
    preg_match('#Down (.*?) Rank#'$string$matches);
    $str $matches[1];
    echo 
    $str;
    ?>
    the $string is a word for word exerpt from the $stats string in the first code. So i figured I could use $string to test out my regex and when i get it to work just replace the static $string with the dynamic string ($stats). The regex above works fine with the static string but when i encorperated it into the larger script it does not work.

    Code:
    <?php
    $url 
    "https://www.novaworld.com/Players/Stats.aspx?id=33680801261&p=616065";

    //Gets the content of the submited URL;
    $content file_get_contents($url); 

    //Strips the tags of the $content;
    $strip strip_tags($content);

    //Removes Everything in the up to For:;
    $remove stristr($strip'Hawk Down');

    //Declares $remove as $getstats;
    $stats $remove;

    preg_match('#Down (.*?) Rank#'$stats$matches);
    $str $matches[1];
    echo 
    $str;

    ?>
    i have no idea what to do. this is the only thing stoping me from progresing with my program and its a pain! any help is appreciated.

    thank you!!
    Last edited by John; 08-04-2006 at 06:33 PM. Reason: adf

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Jordan Guest
    I tried going to the website that you are trying your regex against and it displayed:

    https://www.novaworld.com/Players/Search.aspx

    Do you have to be logged in to see the page? Perhaps that is why your regex isn't working in PHP.

  4. #3
    smith is offline Programmer
    Join Date
    Jun 2006
    Posts
    153
    Rep Power
    0
    I have the same problem as Jordan.
    Code:
    for (int i;;) {
       cout << "Smith";
    }

  5. #4
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    i dont believe you have to be loged in, i just checked it on a different computer in my house and it works fine. Perhaps the website was experience some tech difficulty at the time?

    try it again and if it still dont work, type Ozymandias. (with the period) in the search filed and click the icon under the Stats table heading

  6. #5
    NeedHelp Guest
    Same problem for me. I typed Ozymandias. and clicked on the link. It took me to this page:

    https://www.novaworld.com/Login.aspx...?UserID=428293

    Which is the user logon page.

  7. #6
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    Quote Originally Posted by NeedHelp
    Same problem for me. I typed Ozymandias. and clicked on the link. It took me to this page:

    https://www.novaworld.com/Login.aspx...?UserID=428293

    Which is the user logon page.
    when you searched did you click on the OzymandiasX link or this image?

    https://www.novaworld.com/Images/xDFBHD_75x75.gif

    Clicking the OzymandiasX link will bring up my account information (which you have to be registered to see) clicking the image/icon should allow you to see my stats?

    Im almost 100% sure you dont need to log in to see the stats because i can parse 120 other stats on that page from not only my computer but from my webhosting account (which isnt loged in)

  8. #7
    Jordan Guest
    I get a "No players matched your search." when searching for Ozymandias.

  9. #8
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    eh i changed my username, but if you feel like give it another shot i changed it back.

    anyway lets look beyond trying to get the script to work on your servers, it works on mine fine except for the regex. I think the problem arrises with the string itself. Obviousally the pattern the regex is trying to parse is different from what is being outputed when i echo the $stats string. (well thats the only thing i can conclude)

    So what goes on in these functions that could cause a difference in the actual content verse the echoed content?

    $content = file_get_contents($url);
    $strip = strip_tags($content);

  10. #9
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    Update

    ok the code below works perfect, but it needs to be cleaned up a bit (dont laugh at my regex abilities )

    Code:
    <?php
    $url 
    "https://www.novaworld.com/Players/Stats.aspx?id=8542545489&p=616065";

    //Gets the content of the submited URL;
    $content file_get_contents($url); 

    //Strips the tags of the $content;
    $strip strip_tags($content);
    preg_match('#Down






        
        


        (.*?)
        Rank#'
    $strip$matches);
    $str $matches[1];
    echo 
    $str;
    ?>

  11. #10
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    well it turns out the string was formated like so:


    Player Statistics for Delta Force - Black Hawk Down










    Ozymandias.
    Rank: 1-Star General ( 14 )

    so this did the trick:
    Code:
    preg_match('#Down\s+(.*?)\s+Rank#'$strip$matches); 

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Python ReGex
    By bishisht in forum Python
    Replies: 3
    Last Post: 09-11-2011, 07:00 AM
  2. Need some help with Regex
    By Edvinas in forum C# Programming
    Replies: 3
    Last Post: 06-25-2010, 12:12 PM
  3. RegEx in C++
    By BlaineSch in forum C and C++
    Replies: 2
    Last Post: 11-14-2009, 12:02 AM
  4. Tutorial: C# Regex
    By NeedHelp in forum Tutorials
    Replies: 0
    Last Post: 06-28-2006, 09:27 AM
  5. Tutorial: C# Regex
    By NeedHelp in forum C# Programming
    Replies: 0
    Last Post: 06-28-2006, 09:27 AM

Tags for this Thread

Bookmarks

Posting Permissions

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