473,387 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

need 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_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?

Mar 22 '07 #1
1 3916
On Mar 22, 1:06 pm, "Aaron" <A...@flasemi.comwrote:
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.

Mar 22 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: leegold2 | last post by:
Hi, I have been looking around for a way to paginate php/mysql table output. There are a lot of hits when I google it. But unfortunately what I have tried either does not work or is imho just...
0
by: Phil Powell | last post by:
I am having trouble retrieving URLs using curl for PHP whereby the URL requires a cookie to produce proper data. I wrote a wrapper class called Timer that will time the execution/download of a...
2
by: David Rasmussen | last post by:
Very basic: What is the easiest way in php to download the source code (HTML etc.) of a given URL (say, http://www.google.com) and parse this code for certain patterns? I guess my question...
12
by: | last post by:
Does anyone know an easy way to put a current gold price on your own website? I've seen the graphic methods that Kitco.com offers, but I'd rather have it pull the value from some gold market...
6
by: admin | last post by:
Hi, I have a mysql box that has a private network ip. The old developer was running our web server on this machine but the company since retired the box and it is in a closet, still running, but...
1
by: Aaron | last post by:
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 = "val1"; $post_data = "val2"; $o="";
6
by: junkmate | last post by:
I have made an RSS reader and am testing on the BBC website, and I use this code to grab the contents of the XML file, however when I look at the contents grabbed by my function, and the HTML...
1
by: csteimonts | last post by:
Hey there, if it would be possible, since you have figured out the login function of logging into yahoo from PHP CURL, could you post that solution? I'm having quite a time figuring that...
3
by: GazK | last post by:
I have been using an xml parsing script to parse a number of rss feeds and return relevant results to a database. The script has worked well for a couple of years, despite having very crude...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.