在PHP中包含XML编码

New*_*der 2 php xml

我是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") 
?>
Run Code Online (Sandbox Code Playgroud)

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

Rob*_*Rob 5

在实例化中尝试使用它:

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

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