PHP Scrape (regex) Insert in MySQL

136 Views Asked by At

I'm using the following code to scrape a table:

header('Content-Type: text/html; charset=utf-8'); 

$curl = curl_init('http://www.nhs.uk/service-search/GP/m410ux/Results/4/-2.35167407989502/53.4519462585449/4/0?distance=25');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$page = curl_exec($curl);
if(curl_errno($curl)) // check for execution errors { 
    echo 'Scraper error: ' . curl_error($curl);
    exit; 
}
curl_close($curl);

$regex = '/<table border="1" cellspacing="0" class="items-7" summary="GP    details for the ones you have selected">(.*?)<\/table>/s';
if ( preg_match($regex, $page, $list) )
    echo $list[0];
else 

which outputs the following: http://mt-cloud.co.uk/scrape/

How do I then get each column of the table inserted into a mysql table?

Kindest regards Max

0

There are 0 best solutions below