如何从php文件的开头删除空格?

时间:2016-03-31 07:13:11

标签: php

由于在输出XML文件之前附加了空格,因此有一个正在制作RSS源的PHP文件会出错。我检查了代码和包含变量$s的变量,该变量使得XML文件之前没有任何空格。

<?php

  header("Content-Type: text/xml; encoding=UTF-8");
  $s = "<?xml version='1.0' encoding='UTF-8'?><rss version='2.0'><channel>"; 
 echo ltrim($s);

 foreach($this->results as $row)
  {
     $title=$row->name;
     $description=$row->description;  
     echo "<item><title>$title</title><link>$link</link><description>$description</description></item>"; 
  } 
  echo "</channel></rss>"; 

?>

1 个答案:

答案 0 :(得分:0)

确保<?php

之前没有空格
<?php
header("Content-Type: text/xml; encoding=UTF-8");
$s = "<?xml version='1.0' encoding='UTF-8'?><rss version='2.0'><channel>"; 
echo ltrim($s);

foreach($this->results as $row)
{
$title=$row->name;
$description=$row->description;  
echo "<item><title>$title</title><link>$link</link><description>$description</description></item>"; 
} 

echo "</channel></rss>"; 

?>