Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP DOM XML formatoutput在第一行添加空白_Php_Xml_Domdocument - Fatal编程技术网

PHP DOM XML formatoutput在第一行添加空白

PHP DOM XML formatoutput在第一行添加空白,php,xml,domdocument,Php,Xml,Domdocument,我一直在努力解决这个问题,但我不明白为什么xml文件的第一行有空白 我将XML创建为字符串,如下所示: $xml = '<?xml version="1.0" encoding="utf-8" standalone="no" ?>'; $xml .= '<AuditFile xmlns="urn:OECD:StandardAuditFile-Tax:PT_1.03_01">'; 现在的问题是文件的第一行包含一个空格。 我怎样才能删除它?我尝试过,但没有成功ltrim(

我一直在努力解决这个问题,但我不明白为什么xml文件的第一行有空白

我将XML创建为字符串,如下所示:

$xml  = '<?xml version="1.0" encoding="utf-8" standalone="no" ?>';
$xml .= '<AuditFile xmlns="urn:OECD:StandardAuditFile-Tax:PT_1.03_01">';
现在的问题是文件的第一行包含一个空格。 我怎样才能删除它?我尝试过,但没有成功
ltrim($xmlString)


已解决

我发现问题不在类
DOMDocument
上,而是在允许用户下载文件的函数上

以前我有过这样的经历:

header('Content-Description: File Transfer');
header('Content-Type: text/xml');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));

readfile($file);
这段代码在下载后在文件中添加了额外的空格。为了解决这个问题,我必须在
readfile()之前添加
ob\u clean()

header('Content-Description: File Transfer');
header('Content-Type: text/xml');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));

readfile($file);