11-06-2008, 12:51 AM
|
#5 (permalink)
|
|
The Contributor
Join Date: Nov 2008
Location: Norway
Posts: 58
Thanks: 20
|
Hello,
I made an attempt to solve your "problem", and I came up with the following (thanks to the manual) solution. I am sure there are better ways to do this, but this seems to work:
PHP Code:
<?php
// Create a new cURL resource
$ch = curl_init();
// Set URL and other appropriate options
curl_setopt( $ch, CURLOPT_URL, 'http://localhost/test.html' );
curl_setopt( $ch, CURLOPT_HEADER, 0 );
// Start output buffering to capture page source
ob_start();
// Grab URL and pass it to the browser
curl_exec( $ch );
// Close cURL resource, and free up system resources
curl_close( $ch );
// Store content of output buffering to a variable
$cache = ob_get_contents();
// Clean output buffer
ob_end_clean();
// Perform an expression match
preg_match( "/<tr class=\"alternateRow\">[\s]+<td>([\w\d ,]+)<\/td>[\s]+<td>([\d\"\- ]+)<\/td>[\s]+<td>([\d\"\- ]+)<\/td>/im", $cache, $matches );
// Print the matches
print_r( $matches );
?>
It will find the following code, then put each of the three matches (it returns four matches, actually, including the entire string) into an array:
Code:
<tr class="alternateRow">
<td> Nov 4, 2008 </td>
<td> 4-6" </td>
<td> 8-10"</td>
We will end up with this (at least I did):
Code:
Array
(
[0] => <tr class="alternateRow">
<td> Nov 4, 2008 </td>
<td> 4-6" </td>
<td> 8-10"</td>
[1] => Nov 4, 2008
[2] => 4-6"
[3] => 8-10"
)
Let me know what you think, if it works and if there is anything you would do another way!
Yours,
Runar
|
|
|