簡體   English   中英

PHP:XML解析錯誤:格式不正確

[英]PHP: XML Parsing Error: not well-formed

加載頁面時出現此錯誤,搜索Google時不走運。

XML解析錯誤:格式不正確

位置:// URL

第7行,第103列:

(這只是代碼的一部分,非常簡化。)

<?php

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

echo <<<html
<html>
<head>
<title>Map Project</title>
<meta charset="utf-8">
<script src=http://maps.googleapis.com/maps/api/js?key=AIzaSyDX319H1v1c6xxiVZm-PTuADCnKLZo&sensor=false"></script>
</head>
<body  onload="localStorage.clear();">
html;

// DB Connection codes goes here..

 $query= "SELECT * FROM `mapx`";
    $result = mysqli_query($dbc,$query);
    if (!$result) {
       echo 'ERROR!';
    }

  header("Content-type: text/xml");
       echo '<markers>';
       while ($row = @mysqli_fetch_assoc($result)){
        echo '<marker ';
        echo 'name="' . parseToXML($row['user']) . '" ';
        echo 'lat="' . $row['lat'] . '" ';
        echo 'lng="' . $row['lng'] . '" ';
        echo '/>';
    }

    echo '</markers>';

echo <<<html

//other parts..

</body>
</html>
html;

?>

錯誤指出的部分:

sensor = [HERE]假

我看到你的代碼,你錯過了腳本SRC =這里和echo <<<htmlhtml;只不過是錯誤的代碼應該是這樣的

        <?php

    function parseToXML($htmlStr)
    {
        $xmlStr=str_replace('<','&lt;',$htmlStr);
        $xmlStr=str_replace('>','&gt;',$xmlStr);
        $xmlStr=str_replace('"','&quot;',$xmlStr);
        $xmlStr=str_replace("'",'&#39;',$xmlStr);
        $xmlStr=str_replace("&",'&amp;',$xmlStr);
        return $xmlStr;
    }
    ?>
    <html>
    <head>
    <title>Map Project</title>
    <meta charset="utf-8">
    <script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDX319H1v1c6xxiVZm-PTuADCnKLZo&sensor=false"></script>
    </head>
    <body  onload="localStorage.clear();">

    <?php
    // DB Connection codes goes here..

     $query= "SELECT * FROM `mapx`";
        $result = mysqli_query($dbc,$query);
        if (!$result) {
           echo 'ERROR!';
        }

      header("Content-type: text/xml");
           echo '<markers>';
           while ($row = @mysqli_fetch_assoc($result)){
            echo '<marker ';
            echo 'name="' . parseToXML($row['user']) . '" ';
            echo 'lat="' . $row['lat'] . '" ';
            echo 'lng="' . $row['lng'] . '" ';
            echo '/>';
        }

        echo '</markers>';

   ?>

    //other parts..

    </body>
    </html>

謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM