+ Reply to Thread
Results 1 to 10 of 10

Thread: regex (yuck)

  1. #1
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,885
    Blog Entries
    25

    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 08:33 PM. Reason: adf

  2. #2
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97
    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.

  3. #3
    Programmer smith is an unknown quantity at this point
    Join Date
    Jun 2006
    Posts
    153
    I have the same problem as Jordan.
    Code:
    for (int i;;) {
       cout << "Smith";
    }

  4. #4
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,885
    Blog Entries
    25
    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

  5. #5
    Programming God NeedHelp is on a distinguished road
    Join Date
    May 2006
    Posts
    526
    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.
    I Need Help

  6. #6
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,885
    Blog Entries
    25
    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)

  7. #7
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97
    I get a "No players matched your search." when searching for Ozymandias.

  8. #8
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,885
    Blog Entries
    25
    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);

  9. #9
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,885
    Blog Entries
    25

    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;
    ?>

  10. #10
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,885
    Blog Entries
    25
    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); 

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Tutorial: C# Regex
    By NeedHelp in forum CSharp Tutorials
    Replies: 2
    Last Post: 05-01-2007, 06:44 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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