xml文件的建立和编码[SimpleXMLElement]

最近写一个重写xml文件的程序,没有什么要求,就是编码上边有些困惑,不废话,上代码.

$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8" ?><thumbnails></thumbnails>');
foreach ( $result as $k => $v ) {
$thumb = $xml->addChild('thumbnail');
$thumb->addAttribute('title', $v['title']);
$thumb->addAttribute('target', '_parent');
$thumb->addAttribute('url', 'http://www.zgweb.com');
$thumb->addAttribute('filename', "{$catid}_{$contentid}.jpg");
$thumb->addAttribute('description', $v['description']);
}
$xml->asXML(MG_WEBEXH_ROOT.$xmlFile);


1.使用encoding直接对编码进行限制

2.木有了.

原文地址:https://www.cnblogs.com/imvkmark/p/2317017.html