- // Search for the correct state file - uses file timestamps
- $sRepURL = 'http://planet.openstreetmap.org/replication/minute/';
- $sRep = file_get_contents($sRepURL);
- preg_match_all('#<a href="[0-9]{3}/">([0-9]{3}/)</a> *(([0-9]{2})-([A-z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}))#', $sRep, $aRepMatches, PREG_SET_ORDER);
+ // Search for the correct state file - uses file timestamps so need to sort by date descending
+ $sRepURL = CONST_Replication_Url."/";
+ $sRep = file_get_contents($sRepURL."?C=M;O=D");
+ // download.geofabrik.de: <a href="000/">000/</a></td><td align="right">26-Feb-2013 11:53 </td>
+ // planet.openstreetmap.org: <a href="273/">273/</a> 22-Mar-2013 07:41 -
+ preg_match_all('#<a href="[0-9]{3}/">([0-9]{3}/)</a>.*(([0-9]{2})-([A-z]{3})-([0-9]{4}) ([0-9]{2}):([0-9]{2}))#', $sRep, $aRepMatches, PREG_SET_ORDER);