Curl failure

Discussion in 'PHP' started by promotingspace.net, Apr 17, 2010.

  1. #1
    Hi
    I am trying to get the "level" from this page
    I use this code:
    
    <?php
        $curl = curl_init();
        curl_setopt ($curl, CURLOPT_URL, "http://www.wowarmory.com/character-sheet.xml?r=Garona&cn=Bob");
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    
        $result = curl_exec ($curl);
        curl_close ($curl);
    
    
    if(preg_match('/<character.{1,30} charUrl="r=Garona&amp;cn=Bob".{1,300}level="(\d+)"/s', $result, $match))
    {
        $level=$match[1];
        echo "level is $level ";
    }
    else echo "attemp 1 failed ";
    
    if(preg_match('/<div id="leveltext">"(\d+)"/s' , $result, $match))
    {
        $level=$match[1];
        echo "level is $level ";
    }
    else echo "attemp 2 failed $result";
    ?>
    
    PHP:
    I have put the code here: http://tinyurl.com/y49sg5x
    If you go to the original page, you'll see the following in source code (what I am trying to get in attemp 1)
    <character battleGroup="Rampage" charUrl="r=Garona&amp;cn=Bob" some more stuff (less than 300 chars) level="80" 
    Code (markup):
    and if you look at the source code of my page, where I echo $result, you'll see this code: (what I am trying to get in attemp 2)
    <div id="leveltext">80</div>
    Code (markup):
    But I don't know why it fails when I try to get the information
    Any help would be extremely appreciated
    Thanks in advance
     
    promotingspace.net, Apr 17, 2010 IP
  2. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #2
    Kaizoku, Apr 17, 2010 IP
  3. Brian1970

    Brian1970 Notable Member

    Messages:
    2,886
    Likes Received:
    416
    Best Answers:
    1
    Trophy Points:
    290
    #3
    Depending on your host you may need to get Curl enabled, Hostgator have it disabled by default.

    Thanks Brian
     
    Brian1970, Apr 17, 2010 IP
  4. promotingspace.net

    promotingspace.net Peon

    Messages:
    361
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Solved
    I had just extra ""
     
    Last edited: Apr 17, 2010
    promotingspace.net, Apr 17, 2010 IP
  5. trickyshaun

    trickyshaun Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    if(preg_match('/<div id="leveltext">"(\d+)"/s' , $result, $match))

    Yep ... i don't know why you push some extra " to preg_match ... lol :D
     
    trickyshaun, Apr 17, 2010 IP