dougui4325 2016-03-31 07:13
浏览 58

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

Have a PHP file which is making RSS feeds it is giving error because of the space appending before the output XML file. I have checked the code and the variable containing the variable $s which is making XML file does not have any white space before it.

<?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条回答 默认 最新

  • dtfbj24048 2016-03-31 07:38
    关注

    Make sure no white space before <?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>"; 
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多