【问题标题】:PHP: XML Parsing Error: not well-formedPHP:XML 解析错误:格式不正确
【发布时间】:2017-01-25 04:54:43
【问题描述】:

我在加载页面时收到此错误,搜索 Google 时没有运气..

XML 解析错误:格式不正确

位置://网址

第 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]假

【问题讨论】:

    标签: php xml


    【解决方案1】:

    我看到你在脚本 src= 中错过了 " 的代码,echo &lt;&lt;&lt;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>
    

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多