You are here: Re: need help parsing website with cURL / preg_match « PHP Programming Language « IT news, forums, messages
Re: need help parsing website with cURL / preg_match

Posted by Aaron on 03/22/07 17:50

On Mar 22, 1:06 pm, "Aaron" <A...@flasemi.com> wrote:
> 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_data as $k=>$v)
> {
> $o.= "$k=".utf8_encode($v)."&";
>
> }
>
> $post_data=substr($o,0,-1);
>
> $ch= curl_init();
> curl_setopt($ch, CURLOPT_POST,1);
> curl_setopt($ch, CURLOPT_HEADER,0);
> curl_setopt($ch, CURLOPT_URL,$url);
> curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
> $result = curl_exec($ch);
> curl_close($ch);
>
> $parttern="/<TABLE>(.*)<\/TABLE>/";
> @preg_match($pattern, ????????????????, $matches);
> print_r($matches[1]);
>
> What would I use for the preg_match?

Figured it out.
I was missing the following line:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result now contains data from web page.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация