当我转到服务器中的链接时,出现此错误。找不到

时间:2018-08-29 11:04:59

标签: php

当我转到此API链接

http://srilanka.travel/service/service.php?fun=news&key=L8ZBTzxKRMUS9cPjWUAjGhh2KMcxhBI

我收到此错误:

  

此页面包含以下错误:
  第65行第1行出现错误:编码错误
  下面是直到第一个错误的页面呈现。

这是我的代码:

    <?php
header("Content-type: text/xml");
require_once('config/db_fns.php');


if(isset($_GET['key']) && $_GET['key']=='L8ZBTzxKRMUS9cPjWUAjGhh2KMcxhB') {

if(isset($_GET["fun"]) && $_GET['fun']=='events') { 
    events(); 

    } 

    if(isset($_GET["fun"]) && $_GET['fun']=='news') {   
    news(); 

    }  
}

$myTweets = array();

function events(){

$conn = db_connect();

$qryCat = "SELECT * FROM `upcoming_events` ORDER BY `event_date` DESC LIMIT 2 
"; 
$resCat = $conn->query($qryCat);
$numCats = $resCat->num_rows;
echo "<?xml version='1.0' encoding='UTF-8'?>";
echo '<upcoming_events>';
for ($i=0; $i <$numCats; $i++)
    {
        $rowCat = $resCat->fetch_assoc();

    $date=date("d/m/Y", strtotime($rowCat['event_date']));  
        echo '<event>';
        echo '<title>',htmlentities($rowCat['title']),'</title>';
        echo '<date>',htmlentities($date),'</date>';
        echo '<image>',htmlentities("www.srilanka.travel/image/".$rowCat['image']),'</image>';
        echo '<link>',htmlentities("www.srilanka.travel/upcoming-events&event=".$rowCat['ue_id']),'</link>';

                echo '</event>';
       // $myTweets[$i]["name"] =  $rowCat['name'];
       // $myTweets[$i]["address"] =  $rowCat['address'];

    }

  echo '</upcoming_events>';  
    $conn->close();


}

function news(){



$conn = db_connect();

$qryCat = "SELECT * FROM `travel_news` ORDER BY `tn_id` DESC LIMIT 2  
"; 
$resCat = $conn->query($qryCat);
$numCats = $resCat->num_rows;
echo "<?xml version='1.0' encoding='UTF-8'?>";
echo '<travel_news>';
for ($i=0; $i <$numCats; $i++)
    {
        $rowCat = $resCat->fetch_assoc();

        echo '<news>';
        echo '<title>',htmlentities($rowCat['title']),'</title>';
        echo '<description>',htmlentities($rowCat['small_description']),'</description>';
        echo '<image>',htmlentities("www.srilanka.travel/image/".$rowCat['image']),'</image>';
        echo '<link>',htmlentities("http://www.srilanka.travel/travel-news&news=".$rowCat['tn_id']),'</link>';

                echo '</news>';
       // $myTweets[$i]["name"] =  $rowCat['name'];
       // $myTweets[$i]["address"] =  $rowCat['address'];

    }

  echo '</travel_news>';  
    $conn->close();


}

?>

1 个答案:

答案 0 :(得分:0)

在第64行(引起错误的行之前)使用单引号而不是双引号存在问题。

该行应为

echo '<?xml version="1.0" encoding="UTF-8"?>';

代替

echo "<?xml version='1.0' encoding='UTF-8'?>";