473,657 Members | 2,528 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_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?

Mar 22 '07 #1
1 3622
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).

Mar 22 '07 #2

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

Similar topics

0
2949
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 remote URL and it uses curl as its means of obtaining the URL: class Timer extends View { /** * @access private
2
4542
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 access to the main sql server on campus. I hope to use XML and SSL to transfer student data to the main server. As for generating the XML, I'll have an asp.net page set up in a secure directory that will generate the data in xml format. The...
1
1498
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 open the pages from other websites. With fopen, throught a socket or with a curl.
6
1973
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 sad and alone, aliased as oldserver.mycompany.com. Now I am finding out that I need to use some of the funcitonality in the scripts that are on the old box.
5
3914
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 some reason - and cannot install pecl extensions. Any ideas? Any example scripts? Thanks!!
9
2021
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 it. As you can see at the bottom of the script if (strstr($Line, 'HOUSTON YAMAHA MOTORSPORTS')) then it is reading the correct page, otherwise if (strstr($Line, 'Yamaha Dealer Locator')) then it is reading the incorrect page of the initial URL...
1
3946
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
1093
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... So let's get to the point: If I put this into the browser of choice: http://gateway.mobile-marketing-system.de/send_sms.php?username=KU-1234&password= geheim&text=Dies+ist+ein+Test&recipient=%2B491712345678&sender=%2B491712345678
3
4507
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 error-trapping (if it finds an error in one of the xml files, the script stops). Recently, the script has stopped working because one of the xml files is badly formed. So I decided to rewrite the script with better error trapping; the script should...
0
8425
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8326
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8845
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8743
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8622
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5647
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1973
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.