<?php
include_once("./_common.php");

$zipfile = array();
$fp = fopen($g4['bbs_path']."/zip.db", "r");
while(!feof($fp)) {
    $zipfile[] = fgets($fp, 4096);
}
fclose($fp);

$search_count = 0;

if ($addr1) 
{
    while ($zipcode = each($zipfile)) 
    {
        if(strstr(substr($zipcode[1],9,512), $addr1))
        {
            $list[$search_count][zip1] = substr($zipcode[1],0,3);
            $list[$search_count][zip2] = substr($zipcode[1],4,3);    
            $addr = explode(" ", substr($zipcode[1],8));

            if ($addr[sizeof($addr)-1]) 
            {
                $list[$search_count][addr] = str_replace($addr[sizeof($addr)-1], "", substr($zipcode[1],8));
                $list[$search_count][bunji] = trim($addr[sizeof($addr)-1]);
            }
            else
                $list[$search_count][addr] = substr($zipcode[1],8);

            $list[$search_count][encode_addr] = urlencode($list[$search_count][addr]);
            $search_count++;
        }    
    }

    if (!$search_count) alert("찾으시는 주소가 없습니다.");
}

$g4['title'] = "우편번호 검색";
include_once("{$g4['g4m_path']}/head.sub.php");
$member_skin_path = "{$g4['g4m_path']}/skin/member/{$config['cf_member_skin']}";
include_once("{$member_skin_path}/zip.skin.php");
include_once("{$g4['g4m_path']}/tail.sub.php");