<?
function getcontent($query)
{
global $key;
$cont = "";
$server = "openapi.map.naver.com";
$file = "/api/geocode.php?key=".$key."&encoding=euc-kr&coord=LatLng&query=".$query;
$fp = pfsockopen($server, 80, $errno, $errstr);
if (!$fp) {
echo "$errstr ($errno)<br/>\n";
exit;
} else {
fputs($fp, "GET $file HTTP/1.1\r\n");
fputs($fp, "Host: $server\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fwrite($fp, $out);
while (!feof($fp)) {
$cont .= fgets($fp, 128);
}
fclose($fp);
return $cont;
}
}
function getpoint($data,$start_str,$end_str)
{
$i=0;
while(is_int($pos = strpos($data, $start_str, $i))) {
$pos += strlen($start_str);
$endpos = strpos($data,$end_str, $pos);
$value = substr($data, $pos, $endpos-$pos);
$value_array[] = $value;
$i = $endpos;
}
return $value_array;
}
$key = "키값입력";
$query= str_replace( " ", "", addslashes("주소") );
$data=getcontent($query);
$xpoint=getpoint($data,"<x>","</x>");
$ypoint=getpoint($data,"<y>","</y>");
?>
좌표로 출력
<?=$xpoint[0]?>
<?=$ypoint[0]?>