Can someone help me here? I need to parse some html and get out certain bits of info (lat, long, address.)
Starting content (this will be in a variable):
<tr class="content">
<td height="20"><a class="darkblue" style="text-decoration: none;" href="javascript: GetPosition('2','7','102','1222','149.37958938','-31.55132197','','<b>Your Address Search : <span class=content_red>20 Napier Street, Binnaway, 2395,, NSW</span></b>','6','','');" title="See map">1. 20 Napier Street, Binnaway, 2395, NSW</a><td>
<td align="right"><a href="javascript: GetPosition('2','7','102','1222','149.37958938','-31.55132197','','<b>Your Address Search : <span class=content_red>20 Napier Street, Binnaway, 2395,, NSW</span></b>','6','','');" title="See map">map</a></td>
</tr>
<tr class="content">
<td height="20"><a class="darkblue" style="text-decoration: none;" href="javascript: GetPosition('2','7','102','2189','147.14631044','-33.08389952','','<b>Your Address Search : <span class=content_red>20 Napier Street, Condobolin, 2877,, NSW</span></b>','6','','');" title="See map">2. 20 Napier Street, Condobolin, 2877, NSW</a><td>
<td align="right"><a href="javascript: GetPosition('2','7','102','2189','147.14631044','-33.08389952','','<b>Your Address Search : <span class=content_red>20 Napier Street, Condobolin, 2877,, NSW</span></b>','6','','');" title="See map">map</a></td>
</tr>
<tr class="content">
<td height="20"><a class="darkblue" style="text-decoration: none;" href="javascript: GetPosition('2','7','102','1181','150.93474922','-31.08205908','','<b>Your Address Search : <span class=content_red>20 Napier Street, East Tamworth, 2340,, NSW</span></b>','6','','');" title="See map">3. 20 Napier Street, East Tamworth, 2340, NSW</a><td>
<td align="right"><a href="javascript: GetPosition('2','7','102','1181','150.93474922','-31.08205908','','<b>Your Address Search : <span class=content_red>20 Napier Street, East Tamworth, 2340,, NSW</span></b>','6','','');" title="See map">map</a></td>
</tr>
finishing with an array Ihave used | as a delimiter to illustrate the breaks:
149.37958938 | -31.55132197 | 1. 20 Napier Street, Binnaway, 2395, NSW
147.14631044 | -33.08389952 | 2. 20 Napier Street, Condobolin, 2877, NSW
150.93474922 | -31.08205908 | 3. 20 Napier Street, East Tamworth, 2340, NSW
Thanks!
by: RoonaanPosted on 2006-08-16 at 05:16:48ID: 17325527
Try this:
.+?(\-?\d+ \.\d+).*?< span.*?>([ ^,]+)\s*,\ s*([^,]+?) \s*,\s*([^ ,]+?)\s*,[ ^,]*,\s*([ ^<]+)#is';
<?php
$text = .... your html retrieval here ...
// Length regular expression
$preg = '#<tr.*?<a.+?(\-?\d+\.\d+)
// all results are stored in the $rows array
$rows = array();
// See if records match and fill the $rows array
if(preg_match_all($preg, $text, $match)) {
foreach($match[1] as $i => $a) {
$rows[] = $a.' | '.$match[2][$i].' | '.($i+1).'. '.$match[3][$i].', '.$match[4][$i].', '.$match[5][$i].', '.$match[6][$i];
}
}
echo implode('<br/>', $rows);
?>
-r-