Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将输出保存为.xml格式_Php_Mysql_Xml_Google Maps_Output - Fatal编程技术网

Php 将输出保存为.xml格式

Php 将输出保存为.xml格式,php,mysql,xml,google-maps,output,Php,Mysql,Xml,Google Maps,Output,我在一个示例项目中工作,该项目根据谷歌地图上的区域给出电信运营商手机发射塔的位置 我将遵循谷歌地图API操作指南中的步骤 我被困在这里了。我已经按照所有的说明进行了操作,我还从数据库中获取了网页上的XML输出。现在,按照我必须遵循的说明,我必须将此输出保存到服务器的.XML文件中,以便进一步处理,并在谷歌地图上添加标记。这些标记包括Lat-Long值和所选基站的一些信息:基站id、位置代码和无线电类型 我已经搜索了解决方案,但我一直停留在-PHP:DOMDocument::save和如何在代码

我在一个示例项目中工作,该项目根据谷歌地图上的区域给出电信运营商手机发射塔的位置

我将遵循谷歌地图API操作指南中的步骤

我被困在这里了。我已经按照所有的说明进行了操作,我还从数据库中获取了网页上的XML输出。现在,按照我必须遵循的说明,我必须将此输出保存到服务器的.XML文件中,以便进一步处理,并在谷歌地图上添加标记。这些标记包括Lat-Long值和所选基站的一些信息:基站id、位置代码和无线电类型

我已经搜索了解决方案,但我一直停留在-PHP:DOMDocument::save和如何在代码中实现上

随附的代码仅供参考:

function parseToXML($htmlStr) {
    $xmlStr = str_replace('<','&lt;',$htmlStr);
    $xmlStr = str_replace('>','&gt;',$htmlStr);
    $xmlStr = str_replace('"','&quot;',$htmlStr);
    $xmlStr=str_replace("'",'&#39;',$xmlStr);
    $xmlStr = str_replace('&','&amp;',$htmlStr);
    return $xmlStr;
}


$t_query = "SELECT `radio_type`, `lac`,`cell-id`,`longitude`,`latitude` FROM `".DBNAME."`.`celltower` WHERE `mcc` = '".$mcc."' AND `mnc` = '".$mnc."'";

$t_query_exec = mysqli_query($con, $t_query);

if($t_num_rows = 0) {
    die("Unable to fetch any data..Please try again..!!");
} else {
    header("Content-type: text/xml");

    //Begin XML file, echo parent node.

    echo '<?xml version="1.0" encoding="utf-8"?>';
    echo '<root>';
    echo '<markers>';
    //Iterating through rows, and printing XML nodes for each
    while($t_var = mysqli_fetch_assoc($t_query_exec)) {
        //Add to XML document node.
        echo '<marker ';
        echo 'radio_type="' .parseToXML($t_var['radio_type']) . '" ';
        echo 'lac="' .parseToXML($t_var['lac']) . '" ';
        echo 'cell-id="' .parseToXML($t_var['cell-id']) . '" ';
        echo 'longitude="' . $t_var['longitude'] . '" ';
        echo 'latitude="' .$t_var['latitude'] . '" ';
        echo '/>';
    }

    echo '</markers>';
    echo '</root>'; 
}
我只需要知道如何将输出保存到.XML文件中
提前感谢。

只需将XML放入变量中,并将其与文件内容一起保存即可


谢谢。。我会把它转交给你。。
$xmlString = '<?xml version="1.0" encoding="utf-8"?>';
$xmlString .=  '<root>';
$xmlString .=  '<markers>';
//Iterating through rows, and printing XML nodes for each
while($t_var = mysqli_fetch_assoc($t_query_exec)) {
    //Add to XML document node.
    $xmlString .=  '<marker ';
    $xmlString .=  'radio_type="' .parseToXML($t_var['radio_type']) . '" ';
    $xmlString .=  'lac="' .parseToXML($t_var['lac']) . '" ';
    $xmlString .=  'cell-id="' .parseToXML($t_var['cell-id']) . '" ';
    $xmlString .=  'longitude="' . $t_var['longitude'] . '" ';
    $xmlString .=  'latitude="' .$t_var['latitude'] . '" ';
    $xmlString .=  '/>';
}

$xmlString .=  '</markers>';
$xmlString .=  '</root>';   

file_put_contents('output.xml', $xmlString);