Help parsing website with curl / preg_match

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aaron

    Help parsing website with curl / preg_match

    How do I save the data from a web site so I can parse it using curl?
    Here is what I have so far:

    $url="www.test. com";

    $post_data = array();
    $post_data['var1'] = "val1";
    $post_data['var2'] = "val2";

    $o="";
    foreach($post_d ata as $k=>$v)
    {
    $o.= "$k=".utf8_enco de($v)."&";
    }

    $post_data=subs tr($o,0,-1);

    $ch= curl_init();
    curl_setopt($ch , CURLOPT_POST,1) ;
    curl_setopt($ch , CURLOPT_HEADER, 0);
    curl_setopt($ch , CURLOPT_URL,$ur l);
    curl_setopt($ch , CURLOPT_POSTFIE LDS, $post_data);
    $result = curl_exec($ch);
    curl_close($ch) ;

    $parttern="/<TABLE>(.*)<\/TABLE>/";
    @preg_match($pa ttern, ????????, $matches);
    print_r($matche s[1]);

    What would I use for the preg_match?

  • ZeldorBlat

    #2
    Re: Help parsing website with curl / preg_match

    On Mar 22, 1:22 pm, "Aaron" <A...@flasemi.c omwrote:
    How do I save the data from a web site so I can parse it using curl?
    Here is what I have so far:
    >
    $url="www.test. com";
    >
    $post_data = array();
    $post_data['var1'] = "val1";
    $post_data['var2'] = "val2";
    >
    $o="";
    foreach($post_d ata as $k=>$v)
    {
    $o.= "$k=".utf8_enco de($v)."&";
    >
    }
    >
    $post_data=subs tr($o,0,-1);
    >
    $ch= curl_init();
    curl_setopt($ch , CURLOPT_POST,1) ;
    curl_setopt($ch , CURLOPT_HEADER, 0);
    curl_setopt($ch , CURLOPT_URL,$ur l);
    curl_setopt($ch , CURLOPT_POSTFIE LDS, $post_data);
    $result = curl_exec($ch);
    curl_close($ch) ;
    >
    $parttern="/<TABLE>(.*)<\/TABLE>/";
    @preg_match($pa ttern, ????????, $matches);
    print_r($matche s[1]);
    >
    What would I use for the preg_match?
    You need to:

    curl_setopt($ch , CURLOPT_RETURNT RANSFER, true);

    Then, curl_exec($ch) will return the output (and, in your code above,
    put it in $result).

    Comment

    Working...