background image

$xml .= "</article>\n";

echo $xml;

//  创建 XML 单项
function create_item($title_data, $title_size, $content_data, $pubdate_data)
{
    $item = "<item>\n";
    $item .= "<title size=\"" . $title_size . "\">" . $title_data . "</title>\n";
    $item .= "<content>" . $content_data . "</content>\n";
    $item .= " <pubdate>" . $pubdate_data . "</pubdate>\n";
    $item .= "</item>\n";

    return $item;
}

?>

【DomDocument】
方法 2:使用 DomDocument 生成 XML 文件
创建节点使用 createElement 方法,
创建文本内容使用 createTextNode 方法,
添加子节点使用 appendChild 方法,
创建属性使用 createAttribute 方法
PHP 代码如下:

<?PHP
$data_array = array(
    array(
    'title' => 'title1',
    'content' => 'content1',
        'pubdate' => '2009-10-11',
    ),
    array(
    'title' => 'title2',
    'content' => 'content2',
    'pubdate' => '2009-11-11',
    )
);

//  属性数组
$attribute_array = array(
    'title' => array(