473,503 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3612
On Mar 22, 1:22 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?
You need to:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

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

Mar 22 '07 #2

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

Similar topics

0
2942
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
4531
by: jimb | last post by:
I need some advice on how to securely transfer data between two servers. Here is the situation. We have two sql servers that hold student data. I have full access to my sql server, but only write...
1
1491
by: aka_eu | last post by:
Hi, recently I got a project to get info from different websites and to put the info into a DB. Now, I was wondering what is the best technique to implement something like that. How I should...
6
1966
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...
5
3904
by: Paul | last post by:
I need to get, parse and display RSS feeds while having the ini setting, allow_url_fopen = Off. I used to use (in version 4.1) domxml_open_mem() but it's not longer available in this verison for...
9
2010
by: devranger | last post by:
I am using the below CURL Function and can not figure out why it is not retruning the results from the post. Can anyone take a look and tell me what I may be doing wrong? I am just not seeing...
1
3929
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="";
0
1086
by: Steffen Mutter | last post by:
Hi there! I just want to get this http thing into a dynamic scipt using cURL which - as you might have guessed - I never used before and documentation I found so far is quite unuseful for me......
3
4493
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
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7281
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
7334
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...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
737
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.