PHP XML creator doesn't support Persian/Arabic encoding (UTF-8)

Mohmmed Zaky

New Member
I have a problem with my php XML generator class; I used XML Creator class :\[code\]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();}}?>\[/code\]it generates XML file but doesn't support persian or arabic encoding.\[code\]XML Parsing Error: not well-formedLine Number 3, Column 98: <music name="name1" artist="&Ugrave;&Oslash;&sect;&Uacute;&copy;" album="album1">\[/code\]when I change XML file in notepad it works in persian too, but my php class generates incorrect encoding.tnx for your help.
 
Back
Top