Skip to content

Instantly share code, notes, and snippets.

@unlobito

unlobito/extraer.php

Created Nov 18, 2012
Embed
What would you like to do?
<?php
$url = "http://inposdom.gob.do/codigopostal/jos_codigopostallist.php?start=";
$total = 128;
$postal = Array();
for ($i=0; $i<=$total; $i++) {
$data = file_get_contents($url.($i*2)."1");
preg_match_all('/<tr onmouseover="ew_MouseOver\(event, this\);" onmouseout="ew_MouseOut\(event, this\);" onclick="ew_Click\(event, this\);">(.*?)<\/tr>/s', $data, $areas, PREG_SET_ORDER);
foreach ($areas as $area) {
preg_match_all('/<div>(.*?)<\/div>/s', $area[1], $aData, PREG_SET_ORDER);
$aNombre = mb_convert_case($aData[0][1], MB_CASE_TITLE, "UTF-8");
$aNombre = substr($aNombre, 0, strrpos($aNombre, ','));
echo '"'.$aNombre.'",';
echo '"'.mb_convert_case($aData[1][1], MB_CASE_TITLE, "UTF-8").'",';
echo $aData[2][1]."\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.