Don't be fooled by the View Solution Button. Just scroll down the page for the answer
I can see that
Code:
Accepted Answer from German_Rumm
Date: 04/27/2005 01:18PM PDT
Grade: A
Accepted Answer
lamerhooDJV,
well, for that listing I would use following code:
<?php
$pattern = '/addListing&.*city=(.*?)&state=(.*?)&zip=(.*?)&name=(.*?)&phone=(.*?)&/i';
preg_match_all($pattern, $html, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
list ($city, $state, $zip, $name, $phone) = array_slice($match, 1);
$address = $city;
if (!empty($state)) $address .= ', '.$state;
if (!empty($zip)) $address .= ', '.$zip;
$values[] = '("'.urldecode($name).'", "'.$address.'", "'.urldecode($phone).'")';
}
$sql = 'INSERT INTO table VALUES '.implode(', ', $values);
echo $sql;
?>
You see, all the information you need is really encoded in addListing url (at least in your example it is)
so it's much easier to parse it, than try to extract text from HTML. It also not likely to change with site re-design...
|