CURL HELP Required

Discussion in 'Programming' started by biobrain, Jul 12, 2008.

  1. #1
    I want to curl a page and extract data between a div tag

    <div class="topmasters" align="center"> data required </div>

    here is my code

    // create a new curl resource
    $ch = curl_init();
    
    // set URL and other appropriate options
    curl_setopt($ch, CURLOPT_URL, "http://example.com/");
    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    // grab URL, and return output
    $output = curl_exec($ch);
    
    // close curl resource, and free up system resources
    curl_close($ch);
    
    
    preg_match_all('/<div\s class=\'topmasters\' \s align=\'center\'>(.*?)<\/div>/",$output, $t);
    
    $output=str_replace('/<div\s class=\'topmasters\' \s align=\'center\'>','',$t[0]);
    
    echo $output;
    
    ?>
    
    
    Code (markup):
    Please help to spot the error in the code?
     
    biobrain, Jul 12, 2008 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    preg_match_all('/<div\s class=\'topmasters\' \s align=\'center\'>(.*?)<\/div>/",$output, $t);

    Starts with a single quote, ends with a double for starters...

    Add error_reporting(E_ALL); to your code

    I would also not bother with the \s unless you're sure they're needed.

    Dan
     
    Danltn, Jul 13, 2008 IP