首页 > 解决方案 > 为什么我在使用 PHP 生成的 XML 文件中出现错误

问题描述

我正在使用 php 从一组值创建一个 xml 文件。在函数 saveXml() 之前一切正常。当我打开 xml 时,我发现每 16384 个字符出现一些错误

我的代码:

$db_results = $this->getValues(array('1','2','3'));
        if( @count($db_results) > 0 ){
            $XML = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><dati></dati>');
            $XML->addAttribute('tipologia', '_tipologia1');
            foreach($db_results as $key => $val){
                $blocco_1 = $XML->addChild('blocco1');
                $blocco_1->addAttribute('blocco1_id',$val['id']);
                $blocco_2 = $blocco_1->addChild('info_blocco2');
                $blocco_2->addChild('id',$val['id_td']);
            }
            if(file_exists($this->_export_dir . 'output.xml')) unlink($this->_export_dir . 'output.xml');
            $XML->saveXML($this->_export_dir . 'output.xml');
        }

我无法将错误粘贴到 xml 中。您可以在下面的图片中看到 OUTPUT XML

我尝试增加服务器内存限制,但问题仍然存在。

欢迎任何建议

标签: phpxmlsimplexml

解决方案


推荐阅读