<?php

//もし検索文字列が送られていなければ、検索できない
if (empty($_REQUEST['pref'])) {
    echo "<city>都道府県名が指定されていません</city>";
}
else {
    //検索対象の初めと終わりのホワイトスペースを取り除く
    $search = trim($_REQUEST['pref']);
    switch($search) {
      case "HO" :
        $result = "<city><value>sapporo</value><title>札幌</title></city>" .
                  "<city><value>asahikawa</value><title>旭川</title></city>";
        break;
      case "FU" :
        $result = "<city><value>fukui</value><title>福井</title></city>" .
                  "<city><value>sabae</value><title>鯖江</title></city>" .
                  "<city><value>echizen</value><title>越前</title></city>";
        break;
      case "NA" :
        $result = "<city><value>nagano</value><title>長野</title></city>" .
                  "<city><value>matsumoto</value><title>松本</title></city>" .
                  "<city><value>web2</value><title>Web 3.0 シティ</title></city>" .
                  "<city><value>ueda</value><title>上田</title></city>";
        break;
      case "OK" :
        $result = "<city><value>naha</value><title>那覇</title></city>"  .
                  "<city><value>ishigaki</value><title>石垣</title></city>" 
;
        break;
      default :
        $result = "<city><value></value><title>都市が見つかりません</title></city>";
        break;
    }
    $result ='<?xml version="1.0" encoding="UTF-8" ?>' .
              "<cities>" . $result . "</cities>";

    header("Content-Type: text/xml; charset=utf-8");

    echo $result; // 出力
}
?>
