如何创建一个简单的php文件来生成XML结果

If I enter http://localhost/sitename?filter=city I would like to display all the cities in xml format

I would like the xml display in tag format like this

<city>
   <navi mumbai>
   <pune>
</city>

Here is sample php code , run this code with your link as filter as your condition

    Header("Content-type: text/xml"); 
    // get query string params
    $filter = $_GET['filter'];

    $xml = '';

    If ($filter == "city"){
        $xml = $xml . '<continent name="city">';
        $xml = $xml . '<city id="1">Navi Mumbai</city>';
        $xml = $xml . '<city id="2">Thane</city>';
        $xml = $xml . '<city id="3">Pune</city>';
        $xml = $xml . '</continent>';
    }else If ($filter == "country"){
        $xml = $xml . '<continent name="country">';
        $xml = $xml . '<country id="100">India</country>';
        $xml = $xml . '</continent>';
    }else If ($filter == "state"){
        $xml = $xml . '<continent name="state">';
        $xml = $xml . '<state id="300">Maharastra</state>';
        $xml = $xml . '</continent>';
    }else{
        $xml = $xml . '<continent name="none">';
        $xml = $xml . '<country id="0">no result found</country>';
        $xml = $xml . '</continent>';
    }

    // send xml to client
    echo( $xml );
?>

From you output I assume you want something like this:

<?php
    if (isset($_GET["filter"]))
    {
        $filter = $_GET["filter"];
        // create doctype
        $dom = new DOMDocument("1.0");

        switch($filter)
        {
            case "city":
                // display document in browser as plain text 
                // for readability purposes
                header("Content-Type: text/plain");

                // create root element
                $root = $dom->createElement("cities");
                $dom->appendChild($root);

                // create child element
                $item = $dom->createElement("city1");
                $root->appendChild($item);

                $item = $dom->createElement("city2");
                $root->appendChild($item);
            break;

            default:
                // do something else
        }
        // save and display tree
        echo $dom->saveXML();
    }
?>

Please note that you cannot separate the name of an XML element with space, as you seem to have done in your example.