PHP XML创建者不支持';t支持波斯语/阿拉伯语编码(UTF-8)
我的php XML生成器类有问题;我使用了XML Creator类:PHP XML创建者不支持';t支持波斯语/阿拉伯语编码(UTF-8),php,xml,encoding,Php,Xml,Encoding,我的php XML生成器类有问题;我使用了XML Creator类: class _XmlWriter { var $xml; var $indent; var $stack = array(); function _XmlWriter($indent = ' ') { $this->indent = $indent; $this->xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; } f
class _XmlWriter {
var $xml;
var $indent;
var $stack = array();
function _XmlWriter($indent = ' ') {
$this->indent = $indent;
$this->xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
}
function _indent() {
for ($i = 0, $j = count($this->stack); $i < $j; $i++) {
$this->xml .= $this->indent;
}
}
function push($element, $attributes = array()) {
$this->_indent();
$this->xml .= '<' . $element;
foreach ($attributes as $key => $value) {
$this->xml .= ' ' . $key . '="' . htmlentities($value) . '"';
}
$this->xml .= ">\n";
$this->stack[] = $element;
}
function element($element, $content, $attributes = array()) {
$this->_indent();
$this->xml .= '<' . $element;
foreach ($attributes as $key => $value) {
$this->xml .= ' ' . $key . '="' . htmlentities($value) . '"';
}
$this->xml .= '>' . htmlentities($content) . '</' . $element . '>' . "\n";
}
function emptyelement($element, $attributes = array()) {
$this->_indent();
$this->xml .= '<' . $element;
foreach ($attributes as $key => $value) {
$this->xml .= ' ' . $key . '="' . htmlentities($value) . '"';
}
$this->xml .= " />\n";
}
function pop() {
$element = array_pop($this->stack);
$this->_indent();
$this->xml .= "</$element>\n";
}
function getXml() {
return $this->xml;
}
function create($root, $array) {
$xml = new _XmlWriter();
$xml->push($root);
foreach ($array as $record) {
$xml->push('music', array('name' => $record[0],
'artist' => $record[1],
'album' => $record[2]));
$xml->pop();
}
$xml->pop();
return $xml->getXml();
}
}
?>
class\u XmlWriter{
var$xml;
var$缩进;
var$stack=array();
函数_XmlWriter($indent=''){
$this->indent=$indent;
$this->xml=''。\n;
}
函数_indent(){
对于($i=0,$j=count($this->stack);$i<$j;$i++){
$this->xml.=$this->indent;
}
}
函数push($element,$attributes=array()){
$this->_indent();
$this->xml.=''.htmlentities($content)。''.\n;
}
函数emptyelement($element,$attributes=array()){
$this->_indent();
$this->xml.='我使用了自己编写的函数而不是xml编写器类:
function xml_generator($root, $tag_array, $att_array, $val_array) {
$xml_str = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
$xml_str .= '<' . $root . '>' . "\n";
for ($i = 0; $i < sizeof($val_array); $i++) {
$xml_str .= '<' . $tag_array[$i] . ' ';
for ($j = 0; $j < sizeof($att_array); $j++) {
$xml_str .= $att_array[$j] . '="' . $val_array[$i][$j] . '" ';
}
$xml_str .= '>' . '</' . $tag_array[$i] . '>' . "\n";
}
$xml_str .= '</' . $root . '>';
return $xml_str;
}
函数xml_生成器($root、$tag_数组、$att_数组、$val_数组){
$xml_str=''。\n;
$xml_str.=''。\n;
对于($i=0;$i
现在它支持Unicode(UTF-8)
function xml_generator($root, $tag_array, $att_array, $val_array) {
$xml_str = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
$xml_str .= '<' . $root . '>' . "\n";
for ($i = 0; $i < sizeof($val_array); $i++) {
$xml_str .= '<' . $tag_array[$i] . ' ';
for ($j = 0; $j < sizeof($att_array); $j++) {
$xml_str .= $att_array[$j] . '="' . $val_array[$i][$j] . '" ';
}
$xml_str .= '>' . '</' . $tag_array[$i] . '>' . "\n";
}
$xml_str .= '</' . $root . '>';
return $xml_str;
}