Captain_Glen
July 21st, 2009, 10:16 PM
Hi,
I am trying to scrape a web page using PHP and curl but I don't understand regular expressions. I have read a lot about them on the web but am totally lost.
Here is my code:
<?php
$url = 'http://www.acttab.com.au/interbet/odds?mting=MR01000';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$raw = curl_exec($ch);
$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
$content = str_replace($newlines, "", html_entity_decode($raw));
$start = strpos($content,'<table width=650 border=0 cellspacing=0 cellpadding=3');
// Plus 8 is wrong
$end = strpos($content,'</table>',$start) + 8;
$table = substr($content,$start,$end-$start);
var_dump($table);
preg_match_all("/<tr bgcolor=#eeeeee>(.*)</tr>/", $table, $eRows);
var_dump($eRows);
//preg_match_all("|<tr bgcolor=#bbbbbb>(.*)</tr>|U", $curl_scraped_page, $bRows);
//var_dump($bRows);
curl_close($ch);
echo $curl_scraped_page;
?>
I want to get the rows between <tr bgcolor=#eeeeee> and </tr> But I get this error:
Warning: preg_match_all() [function.preg-match-all]: Unknown modifier 't' in /var/www/php.php on line 18
NULL
Any help would be appreciated.
I am trying to scrape a web page using PHP and curl but I don't understand regular expressions. I have read a lot about them on the web but am totally lost.
Here is my code:
<?php
$url = 'http://www.acttab.com.au/interbet/odds?mting=MR01000';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$raw = curl_exec($ch);
$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
$content = str_replace($newlines, "", html_entity_decode($raw));
$start = strpos($content,'<table width=650 border=0 cellspacing=0 cellpadding=3');
// Plus 8 is wrong
$end = strpos($content,'</table>',$start) + 8;
$table = substr($content,$start,$end-$start);
var_dump($table);
preg_match_all("/<tr bgcolor=#eeeeee>(.*)</tr>/", $table, $eRows);
var_dump($eRows);
//preg_match_all("|<tr bgcolor=#bbbbbb>(.*)</tr>|U", $curl_scraped_page, $bRows);
//var_dump($bRows);
curl_close($ch);
echo $curl_scraped_page;
?>
I want to get the rows between <tr bgcolor=#eeeeee> and </tr> But I get this error:
Warning: preg_match_all() [function.preg-match-all]: Unknown modifier 't' in /var/www/php.php on line 18
NULL
Any help would be appreciated.