gpt4 book ai didi

php - 在 PHP 中包含 XML 编码

转载 作者:数据小太阳 更新时间:2023-10-29 02:48:42 25 4
gpt4 key购买 nike

我是 PHP 和 XML 的初学者。

谁能告诉我在编写新的 xml 文件时如何包含 XML 编码。

代码如下:

writexml.php

<?php 
$ids = array("1", "2", "3", "4", "5");
$names = array("Jean Claude Van Damme", "Scott Adkins", "Dolph Ludgren", "Michael Jai White", "Michael Worth");

$domdoc = new DOMDocument();
$domdoc->formatOutput = true;

$el_actionstars = $domdoc->createElement( "actionstars" );
$domdoc->appendChild( $el_actionstars );

$arr_size = count($ids);

for ($i=0; $i < $arr_size; $i++) {
$el_actionstar = $domdoc->createElement( "actionstar" );

$el_id = $domdoc->createElement( "id" );
$el_id->appendChild( $domdoc->createTextNode($ids[$i] . ""));
$el_actionstar->appendChild($el_id);

$el_name = $domdoc->createElement( "name" );
$el_name->appendChild( $domdoc->createTextNode($names[$i] . ""));
$el_actionstar->appendChild($el_name);


$el_actionstars->appendChild($el_actionstar);
}

echo $domdoc->saveXML();
$domdoc->save("actionstars.xml")
?>

xml 输出为 <?xml version="1.0"?>我想添加编码使其看起来像 <?xml version="1.0" encoding="ISO-8859-1"?> .请帮助...

最佳答案

尝试在您的实例化中使用它:

/**
* <?xml version="1.0" encoding="UTF-8" ?>
*/
$domdoc = new DOMDocument('1.0', 'UTF-8');

如下所示:http://php.net/manual/en/domdocument.construct.php

关于php - 在 PHP 中包含 XML 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6184023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com