下面是我的PHP读取xml的代码。用浏览器读取news.xml文件是正常的。但打开php文件就是乱码。各位大虾能指点一下不?谢谢!!
<?php
$doc = new DOMDocument('1.0', 'utf-8');
$doc->load('news.xml');
$news = $doc->getElementsByTagName("news");
foreach($news as $elem)
{
$titles = $elem->getElementsByTagName("title");
$title = $titles->item(0)->nodeValue;
$authors = $elem->getElementsByTagName( "author" );
$author = $authors->item(0)->nodeValue;
$dates = $elem->getElementsByTagName( "date" );
$date = $dates->item(0)->nodeValue;
$contents = $elem->getElementsByTagName( "content" );
$content = $contents->item(0)->nodeValue;
$keywordss = $elem->getElementsByTagName( "keywords" );
$keywords = $keywordss->item(0)->nodeValue;
echo "$title - $author - $date - $content - $keywords";
}
?>