Insert Screen Scrape Data

Hi all, I’m making a screen scraper to take data from our existing site and to insert it into our new database. The current site does not use a database - frustrating! Just wondering how I can insert all the relevant data, currently everything is being entered as a new row. What would be the best way to do this?

<?php
require('scrapeconnent.php');

//Section for Product Name
$html = file_get_contents('http://www.example.com);
$name = preg_match_all("#<h3 class=\\"product\\"><span style='font-family: Arial;font-size: 18px;'>.*?</span></h3>#", $html, $matches);

foreach($matches[0] as $value):
	$result = html_entity_decode($value);
		$result = str_replace("<h3 class=\\"product\\"><span style='font-family: Arial;font-size: 18px;'>", "", $result);
			$result = str_replace("</span></h3>", "", $result);
				$result = trim($result);
					echo "<br/>";
						echo $result;
$query = mysql_query("INSERT INTO testProds (name, datetime) VALUES ('$result', now())");
endforeach;

//Section for Product Price
$price = preg_match_all("#</span><font size=\\"5px\\">.*?</Actinic:PRICES></h3>#", $html, $match);

foreach($match[0] as $value):
	$result = html_entity_decode($value);
		$result = str_replace("</span><font size=\\"5px\\">", "", $result);
			$result = str_replace("</Actinic:PRICES></h3>", "", $result);
			$result = preg_replace('/^#/', '', $result);
				$result = trim($result);
						echo $result;
							echo "<br/>\
";
$query = mysql_query("INSERT INTO testProds (price) VALUES ('$result')");
endforeach;


?>

I suggest:

  1. closing the quote in

$html = file_get_contents('http://www.example.com);

  1. Using one of the XML extension. you can use ‘DOMDocument::loadHTML’ to create a DOM tree from the HTML input. DOMDocument also has the method ‘loadHTMLFile’.

Read more about DOM here.